When applying the system proxy values really use the values.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob6a9a42331934b2f3e443b9161e426f4dd6422330
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 // manual tab
59 updateManual();
60 updateDevice();
61 ui.radioPdf->setChecked(true);
63 // info tab
64 ui.treeInfo->setAlternatingRowColors(true);
65 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
66 ui.treeInfo->expandAll();
67 ui.treeInfo->setColumnCount(2);
69 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
70 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
71 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
72 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
73 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
74 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
75 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
76 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
77 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
78 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
79 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
80 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
81 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
82 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
83 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
84 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
85 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
86 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
87 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
89 // actions accessible from the menu
90 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
91 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
92 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
93 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
94 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
95 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
96 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
97 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
98 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
99 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
100 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
101 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
103 #if !defined(STATIC)
104 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
105 #else
106 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
107 #endif
109 initIpodpatcher();
110 initSansapatcher();
111 downloadInfo();
116 void RbUtilQt::updateTabs(int count)
118 switch(count) {
119 case 6:
120 updateInfo();
121 break;
122 default:
123 break;
128 void RbUtilQt::downloadInfo()
130 // try to get the current build information
131 daily = new HttpGet(this);
132 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
133 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
134 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
135 daily->setProxy(proxy());
136 if(settings->cacheOffline())
137 daily->setCache(settings->cachePath());
138 qDebug() << "downloading build info";
139 daily->setFile(&buildInfo);
140 daily->getFile(QUrl(settings->serverConfUrl()));
144 void RbUtilQt::downloadDone(bool error)
146 if(error) {
147 qDebug() << "network error:" << daily->error();
148 return;
150 qDebug() << "network status:" << daily->error();
152 buildInfo.open();
153 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
154 buildInfo.close();
155 versmap.insert("arch_rev", info.value("dailies/rev").toString());
156 versmap.insert("arch_date", info.value("dailies/date").toString());
158 bleeding = new HttpGet(this);
159 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
160 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
161 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
162 bleeding->setProxy(proxy());
163 if(settings->cacheOffline())
164 bleeding->setCache(settings->cachePath());
165 bleeding->setFile(&bleedingInfo);
166 bleeding->getFile(QUrl(settings->bleedingInfo()));
168 if(chkConfig(false)) {
169 QApplication::processEvents();
170 QMessageBox::critical(this, tr("Configuration error"),
171 tr("Your configuration is invalid. This is most likely due "
172 "to a new installation of Rockbox Utility or a changed device "
173 "path. The configuation dialog will now open to allow you "
174 "correcting the problem."));
175 configDialog();
180 void RbUtilQt::downloadBleedingDone(bool error)
182 if(error) qDebug() << "network error:" << bleeding->error();
184 bleedingInfo.open();
185 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
186 bleedingInfo.close();
187 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
188 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
189 qDebug() << "versmap =" << versmap;
193 void RbUtilQt::downloadDone(int id, bool error)
195 QString errorString;
196 errorString = tr("Network error: %1. Please check your network and proxy settings.")
197 .arg(daily->errorString());
198 if(error) {
199 QMessageBox::about(this, "Network Error", errorString);
201 qDebug() << "downloadDone:" << id << error;
205 void RbUtilQt::about()
207 QDialog *window = new QDialog(this);
208 Ui::aboutBox about;
209 about.setupUi(window);
210 window->setModal(true);
212 QFile licence(":/docs/gpl-2.0.html");
213 licence.open(QIODevice::ReadOnly);
214 QTextStream c(&licence);
215 QString cline = c.readAll();
216 about.browserLicense->insertHtml(cline);
217 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
218 QFile credits(":/docs/CREDITS");
219 credits.open(QIODevice::ReadOnly);
220 QTextStream r(&credits);
221 QString rline = r.readAll();
222 about.browserCredits->insertPlainText(rline);
223 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
224 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
225 about.labelTitle->setText(title);
226 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
228 window->show();
233 void RbUtilQt::help()
235 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
236 QDesktopServices::openUrl(helpurl);
240 void RbUtilQt::configDialog()
242 Config *cw = new Config(this);
243 cw->setSettings(settings);
244 cw->show();
245 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
246 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
250 void RbUtilQt::updateSettings()
252 qDebug() << "updateSettings()";
253 updateDevice();
254 updateManual();
258 void RbUtilQt::updateDevice()
260 if(!settings->curNeedsBootloader() ) {
261 ui.buttonBootloader->setEnabled(false);
262 ui.buttonRemoveBootloader->setEnabled(false);
263 ui.labelBootloader->setEnabled(false);
264 ui.labelRemoveBootloader->setEnabled(false);
266 else {
267 ui.buttonBootloader->setEnabled(true);
268 ui.labelBootloader->setEnabled(true);
269 if(settings->curBootloaderMethod() == "fwpatcher") {
270 ui.labelRemoveBootloader->setEnabled(false);
271 ui.buttonRemoveBootloader->setEnabled(false);
273 else {
274 ui.labelRemoveBootloader->setEnabled(true);
275 ui.buttonRemoveBootloader->setEnabled(true);
279 // displayed device info
280 QString mountpoint = settings->mountpoint();
281 QString brand = settings->curBrand();
282 QString name = settings->curName();
283 if(name.isEmpty()) name = "&lt;none&gt;";
284 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
285 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
286 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
290 void RbUtilQt::updateManual()
292 if(settings->curPlatform() != "")
294 QString manual= settings->curManual();
296 if(manual == "")
297 manual = "rockbox-" + settings->curPlatform();
298 QString pdfmanual;
299 pdfmanual = settings->manualUrl() + "/" + manual + ".pdf";
300 QString htmlmanual;
301 htmlmanual = settings->manualUrl() + "/" + manual + "/rockbox-build.html";
302 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
303 .arg(pdfmanual));
304 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
305 .arg(htmlmanual));
307 else {
308 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
309 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
310 .arg("http://www.rockbox.org/manual.shtml"));
315 void RbUtilQt::completeInstall()
317 if(chkConfig(true)) return;
318 if(QMessageBox::question(this, tr("Confirm Installation"),
319 tr("Do you really want to make a complete Installation?"),
320 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
322 // create logger
323 logger = new ProgressLoggerGui(this);
324 logger->show();
326 if(smallInstallInner())
327 return;
329 // Fonts
330 m_error = false;
331 m_installed = false;
332 if(!installFontsAuto())
333 return;
334 else
336 // wait for installation finished
337 while(!m_installed)
338 QApplication::processEvents();
340 if(m_error) return;
341 logger->undoAbort();
343 // Doom
344 if(hasDoom())
346 m_error = false;
347 m_installed = false;
348 if(!installDoomAuto())
349 return;
350 else
352 // wait for installation finished
353 while(!m_installed)
354 QApplication::processEvents();
356 if(m_error) return;
359 // theme
360 // this is a window
361 // it has its own logger window,so close our.
362 logger->close();
363 installThemes();
367 void RbUtilQt::smallInstall()
369 if(chkConfig(true)) return;
370 if(QMessageBox::question(this, tr("Confirm Installation"),
371 tr("Do you really want to make a small Installation?"),
372 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
374 // create logger
375 logger = new ProgressLoggerGui(this);
376 logger->show();
378 smallInstallInner();
381 bool RbUtilQt::smallInstallInner()
383 QString mountpoint = settings->mountpoint();
384 // show dialog with error if mount point is wrong
385 if(!QFileInfo(mountpoint).isDir()) {
386 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
387 logger->abort();
388 return true;
390 // Bootloader
391 if(settings->curNeedsBootloader())
393 m_error = false;
394 m_installed = false;
395 if(!installBootloaderAuto())
396 return true;
397 else
399 // wait for boot loader installation finished
400 while(!m_installed)
401 QApplication::processEvents();
403 if(m_error) return true;
404 logger->undoAbort();
407 // Rockbox
408 m_error = false;
409 m_installed = false;
410 if(!installAuto())
411 return true;
412 else
414 // wait for installation finished
415 while(!m_installed)
416 QApplication::processEvents();
419 return false;
422 void RbUtilQt::installdone(bool error)
424 qDebug() << "install done";
425 m_installed = true;
426 m_error = error;
429 void RbUtilQt::installBtn()
431 if(chkConfig(true)) return;
432 install();
435 bool RbUtilQt::installAuto()
437 QString file = QString("%1%2/rockbox.zip")
438 .arg(settings->bleedingUrl(), settings->curPlatform());
440 buildInfo.open();
441 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
442 buildInfo.close();
444 if(settings->curReleased()) {
445 // only set the keys if needed -- querying will yield an empty string
446 // if not set.
447 versmap.insert("rel_rev", settings->lastRelease());
448 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
451 QString myversion = "r" + versmap.value("bleed_rev");
453 ZipInstaller* installer = new ZipInstaller(this);
454 installer->setUrl(file);
455 installer->setProxy(proxy());
456 installer->setLogSection("Rockbox (Base)");
457 installer->setLogVersion(myversion);
458 if(!settings->cacheDisabled())
459 installer->setCache(settings->cachePath());
460 installer->setMountPoint(settings->mountpoint());
461 installer->install(logger);
463 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
465 return true;
468 void RbUtilQt::install()
470 Install *installWindow = new Install(this);
471 installWindow->setSettings(settings);
472 installWindow->setProxy(proxy());
474 buildInfo.open();
475 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
476 buildInfo.close();
478 if(settings->curReleased()) {
479 // only set the keys if needed -- querying will yield an empty string
480 // if not set.
481 versmap.insert("rel_rev", settings->lastRelease());
482 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
484 installWindow->setVersionStrings(versmap);
486 installWindow->show();
489 bool RbUtilQt::installBootloaderAuto()
491 installBootloader();
492 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
493 return !m_error;
496 void RbUtilQt::installBootloaderBtn()
498 if(chkConfig(true)) return;
499 if(QMessageBox::question(this, tr("Confirm Installation"),
500 tr("Do you really want to install the Bootloader?"),
501 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
503 // create logger
504 logger = new ProgressLoggerGui(this);
505 logger->show();
507 installBootloader();
510 void RbUtilQt::installBootloader()
512 QString platform = settings->curPlatform();
514 // create installer
515 blinstaller = new BootloaderInstaller(this);
517 blinstaller->setMountPoint(settings->mountpoint());
519 blinstaller->setProxy(proxy());
520 blinstaller->setDevice(platform);
521 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
522 blinstaller->setBootloaderName(settings->curBootloaderName());
523 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
524 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
525 if(!blinstaller->downloadInfo())
527 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
528 logger->abort();
529 m_error = true;
530 return;
533 if(blinstaller->uptodate())
535 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
536 tr("The bootloader is already installed and up to date.\n"
537 "Do want to replace the current bootloader?"),
538 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
539 if(ret == QMessageBox::No)
541 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
542 logger->abort();
543 m_installed = true;
544 return;
548 // if fwpatcher , ask for extra file
549 QString offirmware;
550 if(settings->curBootloaderMethod() == "fwpatcher")
552 BrowseOF ofbrowser(this);
553 ofbrowser.setFile(settings->ofPath());
554 if(ofbrowser.exec() == QDialog::Accepted)
556 offirmware = ofbrowser.getFile();
557 qDebug() << offirmware;
558 if(!QFileInfo(offirmware).exists())
560 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
561 logger->abort();
562 m_error = true;
563 return;
565 else
567 settings->setOfPath(offirmware);
568 settings->sync();
571 else
573 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
574 logger->abort();
575 m_error = true;
576 return;
579 blinstaller->setOrigFirmwarePath(offirmware);
581 blinstaller->install(logger);
584 void RbUtilQt::installFontsBtn()
586 if(chkConfig(true)) return;
587 if(QMessageBox::question(this, tr("Confirm Installation"),
588 tr("Do you really want to install the fonts package?"),
589 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
590 // create logger
591 logger = new ProgressLoggerGui(this);
592 logger->show();
593 installFonts();
596 bool RbUtilQt::installFontsAuto()
598 installFonts();
599 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
600 return !m_error;
603 void RbUtilQt::installFonts()
605 // create zip installer
606 installer = new ZipInstaller(this);
608 installer->setUrl(settings->fontUrl());
609 installer->setProxy(proxy());
610 installer->setLogSection("Fonts");
611 installer->setLogVersion(versmap.value("arch_date"));
612 installer->setMountPoint(settings->mountpoint());
613 if(!settings->cacheDisabled())
614 installer->setCache(settings->cachePath());
615 installer->install(logger);
619 void RbUtilQt::installVoice()
621 if(chkConfig(true)) return;
622 if(QMessageBox::question(this, tr("Confirm Installation"),
623 tr("Do you really want to install the voice file?"),
624 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
625 // create logger
626 logger = new ProgressLoggerGui(this);
627 logger->show();
629 // create zip installer
630 installer = new ZipInstaller(this);
631 installer->setUnzip(false);
633 QString voiceurl = settings->voiceUrl() + "/" ;
635 voiceurl += settings->curVoiceName() + "-" +
636 versmap.value("arch_date") + "-english.voice";
637 qDebug() << voiceurl;
639 installer->setProxy(proxy());
640 installer->setUrl(voiceurl);
641 installer->setLogSection("Voice");
642 installer->setLogVersion(versmap.value("arch_date"));
643 installer->setMountPoint(settings->mountpoint());
644 installer->setTarget("/.rockbox/langs/english.voice");
645 if(!settings->cacheDisabled())
646 installer->setCache(settings->cachePath());
647 installer->install(logger);
651 void RbUtilQt::installDoomBtn()
653 if(chkConfig(true)) return;
654 if(!hasDoom()){
655 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
656 return;
659 if(QMessageBox::question(this, tr("Confirm Installation"),
660 tr("Do you really want to install the game addon files?"),
661 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
662 // create logger
663 logger = new ProgressLoggerGui(this);
664 logger->show();
666 installDoom();
668 bool RbUtilQt::installDoomAuto()
670 installDoom();
671 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
672 return !m_error;
675 bool RbUtilQt::hasDoom()
677 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
678 return doomrock.exists();
681 void RbUtilQt::installDoom()
683 // create zip installer
684 installer = new ZipInstaller(this);
686 installer->setUrl(settings->doomUrl());
687 installer->setProxy(proxy());
688 installer->setLogSection("Game Addons");
689 installer->setLogVersion(versmap.value("arch_date"));
690 installer->setMountPoint(settings->mountpoint());
691 if(!settings->cacheDisabled())
692 installer->setCache(settings->cachePath());
693 installer->install(logger);
697 void RbUtilQt::installThemes()
699 if(chkConfig(true)) return;
700 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
701 tw->setSettings(settings);
702 tw->setProxy(proxy());
703 tw->setModal(true);
704 tw->show();
707 void RbUtilQt::createTalkFiles(void)
709 if(chkConfig(true)) return;
710 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
711 installWindow->setSettings(settings);
712 installWindow->show();
713 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
714 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
718 void RbUtilQt::createVoiceFile(void)
720 if(chkConfig(true)) return;
721 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
722 installWindow->setSettings(settings);
723 installWindow->setProxy(proxy());
725 installWindow->show();
726 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
727 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
730 void RbUtilQt::uninstall(void)
732 if(chkConfig(true)) return;
733 UninstallWindow *uninstallWindow = new UninstallWindow(this);
734 uninstallWindow->setSettings(settings);
735 uninstallWindow->show();
739 void RbUtilQt::uninstallBootloader(void)
741 if(chkConfig(true)) return;
742 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
743 tr("Do you really want to uninstall the Bootloader?"),
744 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
745 // create logger
746 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
747 logger->show();
749 BootloaderInstaller blinstaller(this);
750 blinstaller.setProxy(proxy());
751 blinstaller.setMountPoint(settings->mountpoint());
752 blinstaller.setDevice(settings->curPlatform());
753 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
754 blinstaller.setBootloaderName(settings->curBootloaderName());
755 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
756 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
757 if(!blinstaller.downloadInfo())
759 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
760 logger->abort();
761 return;
764 blinstaller.uninstall(logger);
769 void RbUtilQt::downloadManual(void)
771 if(chkConfig(true)) return;
772 if(QMessageBox::question(this, tr("Confirm download"),
773 tr("Do you really want to download the manual? The manual will be saved "
774 "to the root folder of your player."),
775 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
776 return;
778 buildInfo.open();
779 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
780 buildInfo.close();
782 QString manual = settings->curManual();
784 QString date = (info.value("dailies/date").toString());
786 QString manualurl;
787 QString target;
788 QString section;
789 if(ui.radioPdf->isChecked()) {
790 target = "/" + manual + ".pdf";
791 section = "Manual (PDF)";
793 else {
794 target = "/" + manual + "-" + date + "-html.zip";
795 section = "Manual (HTML)";
797 manualurl = settings->manualUrl() + "/" + target;
798 qDebug() << "manualurl =" << manualurl;
800 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
801 logger->show();
802 installer = new ZipInstaller(this);
803 installer->setMountPoint(settings->mountpoint());
804 if(!settings->cacheDisabled())
805 installer->setCache(settings->cachePath());
806 installer->setProxy(proxy());
807 installer->setLogSection(section);
808 installer->setLogVersion(date);
809 installer->setUrl(manualurl);
810 installer->setUnzip(false);
811 installer->setTarget(target);
812 installer->install(logger);
816 void RbUtilQt::installPortable(void)
818 if(QMessageBox::question(this, tr("Confirm installation"),
819 tr("Do you really want to install Rockbox Utility to your player? "
820 "After installation you can run it from the players hard drive."),
821 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
822 return;
824 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
825 logger->setProgressMax(0);
826 logger->setProgressValue(0);
827 logger->show();
828 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
830 // check mountpoint
831 if(!QFileInfo(settings->mountpoint()).isDir()) {
832 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
833 logger->abort();
834 return;
837 // remove old files first.
838 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
839 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
840 // copy currently running binary and currently used settings file
841 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
842 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
843 logger->abort();
844 return;
846 logger->addItem(tr("Installing user configuration"), LOGINFO);
847 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
848 logger->addItem(tr("Error installing user configuration"), LOGERROR);
849 logger->abort();
850 return;
852 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
853 logger->abort();
854 logger->setProgressMax(1);
855 logger->setProgressValue(1);
860 void RbUtilQt::updateInfo()
862 qDebug() << "RbUtilQt::updateInfo()";
864 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
865 QStringList groups = log.childGroups();
866 QList<QTreeWidgetItem *> items;
867 QTreeWidgetItem *w, *w2;
868 QString min, max;
869 int olditems = 0;
871 // remove old list entries (if any)
872 int l = ui.treeInfo->topLevelItemCount();
873 while(l--) {
874 QTreeWidgetItem *m;
875 m = ui.treeInfo->takeTopLevelItem(l);
876 // delete childs (single level deep, no recursion here)
877 int n = m->childCount();
878 while(n--)
879 delete m->child(n);
881 // get and populate new items
882 for(int a = 0; a < groups.size(); a++) {
883 log.beginGroup(groups.at(a));
884 QStringList keys = log.allKeys();
885 w = new QTreeWidgetItem;
886 w->setFlags(Qt::ItemIsEnabled);
887 w->setText(0, groups.at(a));
888 items.append(w);
889 // get minimum and maximum version information so we can hilight old files
890 min = max = log.value(keys.at(0)).toString();
891 for(int b = 0; b < keys.size(); b++) {
892 if(log.value(keys.at(b)).toString() > max)
893 max = log.value(keys.at(b)).toString();
894 if(log.value(keys.at(b)).toString() < min)
895 min = log.value(keys.at(b)).toString();
898 for(int b = 0; b < keys.size(); b++) {
899 QString file;
900 file = settings->mountpoint() + "/" + keys.at(b);
901 if(QFileInfo(file).isDir())
902 continue;
903 w2 = new QTreeWidgetItem(w, QStringList() << "/"
904 + keys.at(b) << log.value(keys.at(b)).toString());
905 if(log.value(keys.at(b)).toString() != max) {
906 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
907 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
908 olditems++;
910 items.append(w2);
912 log.endGroup();
913 if(min != max)
914 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
915 else
916 w->setData(1, Qt::DisplayRole, max);
918 ui.treeInfo->insertTopLevelItems(0, items);
919 ui.treeInfo->resizeColumnToContents(0);
923 QUrl RbUtilQt::proxy()
925 if(settings->proxyType() == "manual")
926 return QUrl(settings->proxy());
927 else if(settings->proxy() == "system")
929 return systemProxy();
931 return QUrl("");
935 bool RbUtilQt::chkConfig(bool warn)
937 bool error = false;
938 if(settings->curPlatform().isEmpty()
939 || settings->mountpoint().isEmpty()
940 || !QFileInfo(settings->mountpoint()).isWritable()) {
941 error = true;
943 if(warn) QMessageBox::critical(this, tr("Configuration error"),
944 tr("Your configuration is invalid. Please go to the configuration "
945 "dialog and make sure the selected values are correct."));
947 return error;