Let qmake generate an install Makefile target to install the binary. Doesn't handle...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob510feb47430cb11b67fa35d13fea65ab7975155b
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"
38 #if defined(Q_OS_LINUX)
39 #include <stdio.h>
40 #endif
41 #if defined(Q_OS_WIN32)
42 #if defined(UNICODE)
43 #define _UNICODE
44 #endif
45 #include <stdio.h>
46 #include <tchar.h>
47 #include <windows.h>
48 #endif
50 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
52 absolutePath = qApp->applicationDirPath();
54 ui.setupUi(this);
56 settings = new RbSettings();
57 settings->open();
59 m_gotInfo = false;
61 // manual tab
62 updateSettings();
63 ui.radioPdf->setChecked(true);
65 // info tab
66 ui.treeInfo->setAlternatingRowColors(true);
67 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
68 ui.treeInfo->expandAll();
69 ui.treeInfo->setColumnCount(2);
71 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
72 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
73 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
74 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
75 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
76 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
77 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
78 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
79 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
80 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
81 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
82 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
83 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
84 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
85 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
86 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
87 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
88 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
89 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
91 // actions accessible from the menu
92 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
93 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
94 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
95 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
96 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
97 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
98 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
99 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
100 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
101 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
102 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
103 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
105 #if !defined(STATIC)
106 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
107 #else
108 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
109 #endif
111 initIpodpatcher();
112 initSansapatcher();
113 downloadInfo();
118 void RbUtilQt::updateTabs(int count)
120 switch(count) {
121 case 6:
122 updateInfo();
123 break;
124 default:
125 break;
130 void RbUtilQt::downloadInfo()
132 // try to get the current build information
133 daily = new HttpGet(this);
134 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
135 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
136 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
137 if(settings->cacheOffline())
138 daily->setCache(true);
139 else
140 daily->setCache(false);
141 qDebug() << "downloading build info";
142 daily->setFile(&buildInfo);
143 daily->getFile(QUrl(settings->serverConfUrl()));
147 void RbUtilQt::downloadDone(bool error)
149 if(error) {
150 qDebug() << "network error:" << daily->error();
151 return;
153 qDebug() << "network status:" << daily->error();
155 buildInfo.open();
156 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
157 buildInfo.close();
158 versmap.insert("arch_rev", info.value("dailies/rev").toString());
159 versmap.insert("arch_date", info.value("dailies/date").toString());
161 bleeding = new HttpGet(this);
162 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
163 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
164 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
165 if(settings->cacheOffline())
166 bleeding->setCache(true);
167 bleeding->setFile(&bleedingInfo);
168 bleeding->getFile(QUrl(settings->bleedingInfo()));
170 if(chkConfig(false)) {
171 QApplication::processEvents();
172 QMessageBox::critical(this, tr("Configuration error"),
173 tr("Your configuration is invalid. This is most likely due "
174 "to a new installation of Rockbox Utility or a changed device "
175 "path. The configuation dialog will now open to allow you "
176 "correcting the problem."));
177 configDialog();
182 void RbUtilQt::downloadBleedingDone(bool error)
184 if(error) qDebug() << "network error:" << bleeding->error();
186 bleedingInfo.open();
187 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
188 bleedingInfo.close();
189 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
190 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
191 qDebug() << "versmap =" << versmap;
193 m_gotInfo = true;
197 void RbUtilQt::downloadDone(int id, bool error)
199 QString errorString;
200 errorString = tr("Network error: %1. Please check your network and proxy settings.")
201 .arg(daily->errorString());
202 if(error) {
203 QMessageBox::about(this, "Network Error", errorString);
205 qDebug() << "downloadDone:" << id << error;
209 void RbUtilQt::about()
211 QDialog *window = new QDialog(this);
212 Ui::aboutBox about;
213 about.setupUi(window);
214 window->setModal(true);
216 QFile licence(":/docs/gpl-2.0.html");
217 licence.open(QIODevice::ReadOnly);
218 QTextStream c(&licence);
219 QString cline = c.readAll();
220 about.browserLicense->insertHtml(cline);
221 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
222 QFile credits(":/docs/CREDITS");
223 credits.open(QIODevice::ReadOnly);
224 QTextStream r(&credits);
225 QString rline = r.readAll();
226 about.browserCredits->insertPlainText(rline);
227 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
228 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
229 about.labelTitle->setText(title);
230 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
232 window->show();
237 void RbUtilQt::help()
239 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
240 QDesktopServices::openUrl(helpurl);
244 void RbUtilQt::configDialog()
246 Config *cw = new Config(this);
247 cw->setSettings(settings);
248 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
249 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
250 cw->show();
254 void RbUtilQt::updateSettings()
256 qDebug() << "updateSettings()";
257 updateDevice();
258 updateManual();
259 if(settings->proxyType() == "system") {
260 HttpGet::setGlobalProxy(systemProxy());
262 else if(settings->proxyType() == "manual") {
263 HttpGet::setGlobalProxy(settings->proxy());
265 else {
266 HttpGet::setGlobalProxy(QUrl(""));
268 HttpGet::setGlobalCache(settings->cachePath());
269 HttpGet::setGlobalDumbCache(settings->cacheOffline());
273 void RbUtilQt::updateDevice()
275 if(!settings->curNeedsBootloader() ) {
276 ui.buttonBootloader->setEnabled(false);
277 ui.buttonRemoveBootloader->setEnabled(false);
278 ui.labelBootloader->setEnabled(false);
279 ui.labelRemoveBootloader->setEnabled(false);
281 else {
282 ui.buttonBootloader->setEnabled(true);
283 ui.labelBootloader->setEnabled(true);
284 if(settings->curBootloaderMethod() == "fwpatcher") {
285 ui.labelRemoveBootloader->setEnabled(false);
286 ui.buttonRemoveBootloader->setEnabled(false);
288 else {
289 ui.labelRemoveBootloader->setEnabled(true);
290 ui.buttonRemoveBootloader->setEnabled(true);
294 // displayed device info
295 QString mountpoint = settings->mountpoint();
296 QString brand = settings->curBrand();
297 QString name = settings->curName();
298 if(name.isEmpty()) name = "&lt;none&gt;";
299 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
300 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
301 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
305 void RbUtilQt::updateManual()
307 if(settings->curPlatform() != "")
309 QString manual= settings->curManual();
311 if(manual == "")
312 manual = "rockbox-" + settings->curPlatform();
313 QString pdfmanual;
314 pdfmanual = settings->manualUrl() + "/" + manual + ".pdf";
315 QString htmlmanual;
316 htmlmanual = settings->manualUrl() + "/" + manual + "/rockbox-build.html";
317 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
318 .arg(pdfmanual));
319 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
320 .arg(htmlmanual));
322 else {
323 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
324 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
325 .arg("http://www.rockbox.org/manual.shtml"));
330 void RbUtilQt::completeInstall()
332 if(chkConfig(true)) return;
333 if(QMessageBox::question(this, tr("Confirm Installation"),
334 tr("Do you really want to make a complete Installation?"),
335 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
337 // create logger
338 logger = new ProgressLoggerGui(this);
339 logger->show();
341 if(smallInstallInner())
342 return;
343 logger->undoAbort();
344 // Fonts
345 m_error = false;
346 m_installed = false;
347 if(!installFontsAuto())
348 return;
349 else
351 // wait for installation finished
352 while(!m_installed)
353 QApplication::processEvents();
355 if(m_error) return;
356 logger->undoAbort();
358 // Doom
359 if(hasDoom())
361 m_error = false;
362 m_installed = false;
363 if(!installDoomAuto())
364 return;
365 else
367 // wait for installation finished
368 while(!m_installed)
369 QApplication::processEvents();
371 if(m_error) return;
374 // theme
375 // this is a window
376 // it has its own logger window,so close our.
377 logger->close();
378 installThemes();
382 void RbUtilQt::smallInstall()
384 if(chkConfig(true)) return;
385 if(QMessageBox::question(this, tr("Confirm Installation"),
386 tr("Do you really want to make a small Installation?"),
387 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
389 // create logger
390 logger = new ProgressLoggerGui(this);
391 logger->show();
393 smallInstallInner();
396 bool RbUtilQt::smallInstallInner()
398 QString mountpoint = settings->mountpoint();
399 // show dialog with error if mount point is wrong
400 if(!QFileInfo(mountpoint).isDir()) {
401 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
402 logger->abort();
403 return true;
405 // Bootloader
406 if(settings->curNeedsBootloader())
408 m_error = false;
409 m_installed = false;
410 if(!installBootloaderAuto())
411 return true;
412 else
414 // wait for boot loader installation finished
415 while(!m_installed)
416 QApplication::processEvents();
418 if(m_error) return true;
419 logger->undoAbort();
422 // Rockbox
423 m_error = false;
424 m_installed = false;
425 if(!installAuto())
426 return true;
427 else
429 // wait for installation finished
430 while(!m_installed)
431 QApplication::processEvents();
434 return false;
437 void RbUtilQt::installdone(bool error)
439 qDebug() << "install done";
440 m_installed = true;
441 m_error = error;
444 void RbUtilQt::installBtn()
446 if(chkConfig(true)) return;
447 install();
450 bool RbUtilQt::installAuto()
452 QString file = QString("%1%2/rockbox.zip")
453 .arg(settings->bleedingUrl(), settings->curPlatform());
455 buildInfo.open();
456 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
457 buildInfo.close();
459 if(settings->curReleased()) {
460 // only set the keys if needed -- querying will yield an empty string
461 // if not set.
462 versmap.insert("rel_rev", settings->lastRelease());
463 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
466 QString myversion = "r" + versmap.value("bleed_rev");
468 //! check if rockbox is already installed
469 QString rbVersion = installedVersion(settings->mountpoint());
470 if(rbVersion != "")
472 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
473 tr("Rockbox installation detected. Do you want to backup first?"),
474 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
476 logger->addItem(tr("Beginning Backup..."),LOGINFO);
477 QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
479 //! create dir, if it doesnt exist
480 QFileInfo backupFile(backupName);
481 if(!QDir(backupFile.path()).exists())
483 QDir a;
484 a.mkpath(backupFile.path());
487 //! create backup
488 RbZip backup;
489 connect(&backup,SIGNAL(zipProgress(int,int)),this,SLOT(updateDataReadProgress(int,int)));
490 if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
492 logger->addItem(tr("Backup successfull"),LOGOK);
494 else
496 logger->addItem(tr("Backup failed!"),LOGERROR);
497 logger->abort();
498 return false;
503 //! install current build
504 ZipInstaller* installer = new ZipInstaller(this);
505 installer->setUrl(file);
506 installer->setLogSection("Rockbox (Base)");
507 installer->setLogVersion(myversion);
508 if(!settings->cacheDisabled())
509 installer->setCache(true);
510 installer->setMountPoint(settings->mountpoint());
512 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
514 installer->install(logger);
515 return true;
518 void RbUtilQt::updateDataReadProgress(int read, int total)
520 logger->setProgressMax(total);
521 logger->setProgressValue(read);
522 //qDebug() << "progress:" << read << "/" << total;
526 void RbUtilQt::install()
528 Install *installWindow = new Install(settings,this);
530 buildInfo.open();
531 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
532 buildInfo.close();
534 if(settings->curReleased()) {
535 // only set the keys if needed -- querying will yield an empty string
536 // if not set.
537 versmap.insert("rel_rev", settings->lastRelease());
538 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
540 installWindow->setVersionStrings(versmap);
542 installWindow->show();
545 bool RbUtilQt::installBootloaderAuto()
547 installBootloader();
548 return !m_error;
551 void RbUtilQt::installBootloaderBtn()
553 if(chkConfig(true)) return;
554 if(QMessageBox::question(this, tr("Confirm Installation"),
555 tr("Do you really want to install the Bootloader?"),
556 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
558 // create logger
559 logger = new ProgressLoggerGui(this);
560 logger->show();
562 installBootloader();
565 void RbUtilQt::installBootloader()
567 QString platform = settings->curPlatform();
569 // create installer
570 blinstaller = new BootloaderInstaller(this);
572 blinstaller->setMountPoint(settings->mountpoint());
574 blinstaller->setDevice(platform);
575 blinstaller->setBootloaderMethod(settings->curBootloaderMethod());
576 blinstaller->setBootloaderName(settings->curBootloaderName());
577 blinstaller->setBootloaderBaseUrl(settings->bootloaderUrl());
578 blinstaller->setBootloaderInfoUrl(settings->bootloaderInfoUrl());
579 if(!blinstaller->downloadInfo())
581 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
582 logger->abort();
583 m_error = true;
584 return;
587 if(blinstaller->uptodate())
589 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
590 tr("The bootloader is already installed and up to date.\n"
591 "Do want to replace the current bootloader?"),
592 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
593 if(ret == QMessageBox::No)
595 logger->addItem(tr("Bootloader installation skipped!"), LOGINFO);
596 logger->abort();
597 m_installed = true;
598 return;
602 // if fwpatcher , ask for extra file
603 QString offirmware;
604 if(settings->curBootloaderMethod() == "fwpatcher")
606 BrowseOF ofbrowser(this);
607 ofbrowser.setFile(settings->ofPath());
608 if(ofbrowser.exec() == QDialog::Accepted)
610 offirmware = ofbrowser.getFile();
611 qDebug() << offirmware;
612 if(!QFileInfo(offirmware).exists())
614 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
615 logger->abort();
616 m_error = true;
617 return;
619 else
621 settings->setOfPath(offirmware);
622 settings->sync();
625 else
627 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
628 logger->abort();
629 m_error = true;
630 return;
633 blinstaller->setOrigFirmwarePath(offirmware);
634 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
635 blinstaller->install(logger);
638 void RbUtilQt::installFontsBtn()
640 if(chkConfig(true)) return;
641 if(QMessageBox::question(this, tr("Confirm Installation"),
642 tr("Do you really want to install the fonts package?"),
643 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
644 // create logger
645 logger = new ProgressLoggerGui(this);
646 logger->show();
647 installFonts();
650 bool RbUtilQt::installFontsAuto()
652 installFonts();
654 return !m_error;
657 void RbUtilQt::installFonts()
659 // create zip installer
660 installer = new ZipInstaller(this);
662 installer->setUrl(settings->fontUrl());
663 installer->setLogSection("Fonts");
664 installer->setLogVersion(versmap.value("arch_date"));
665 installer->setMountPoint(settings->mountpoint());
666 if(!settings->cacheDisabled())
667 installer->setCache(true);
669 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
670 installer->install(logger);
674 void RbUtilQt::installVoice()
676 if(chkConfig(true)) return;
678 if(m_gotInfo == false)
680 QMessageBox::warning(this, tr("Warning"),
681 tr("The Application is still downloading Information about new Builds. Please try again shortly."));
682 return;
685 if(QMessageBox::question(this, tr("Confirm Installation"),
686 tr("Do you really want to install the voice file?"),
687 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
688 // create logger
689 logger = new ProgressLoggerGui(this);
690 logger->show();
692 // create zip installer
693 installer = new ZipInstaller(this);
695 QString voiceurl = settings->voiceUrl();
697 voiceurl += settings->curVoiceName() + "-" +
698 versmap.value("arch_date") + "-english.zip";
699 qDebug() << voiceurl;
701 installer->setUrl(voiceurl);
702 installer->setLogSection("Voice");
703 installer->setLogVersion(versmap.value("arch_date"));
704 installer->setMountPoint(settings->mountpoint());
705 if(!settings->cacheDisabled())
706 installer->setCache(true);
707 installer->install(logger);
711 void RbUtilQt::installDoomBtn()
713 if(chkConfig(true)) return;
714 if(!hasDoom()){
715 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
716 return;
719 if(QMessageBox::question(this, tr("Confirm Installation"),
720 tr("Do you really want to install the game addon files?"),
721 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
722 // create logger
723 logger = new ProgressLoggerGui(this);
724 logger->show();
726 installDoom();
728 bool RbUtilQt::installDoomAuto()
730 installDoom();
731 return !m_error;
734 bool RbUtilQt::hasDoom()
736 QFile doomrock(settings->mountpoint() +"/.rockbox/rocks/games/doom.rock");
737 return doomrock.exists();
740 void RbUtilQt::installDoom()
742 // create zip installer
743 installer = new ZipInstaller(this);
745 installer->setUrl(settings->doomUrl());
746 installer->setLogSection("Game Addons");
747 installer->setLogVersion(versmap.value("arch_date"));
748 installer->setMountPoint(settings->mountpoint());
749 if(!settings->cacheDisabled())
750 installer->setCache(true);
751 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
752 installer->install(logger);
756 void RbUtilQt::installThemes()
758 if(chkConfig(true)) return;
759 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
760 tw->setSettings(settings);
761 tw->setModal(true);
762 tw->show();
765 void RbUtilQt::createTalkFiles(void)
767 if(chkConfig(true)) return;
768 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
769 installWindow->setSettings(settings);
771 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
772 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
773 installWindow->show();
777 void RbUtilQt::createVoiceFile(void)
779 if(chkConfig(true)) return;
780 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
781 installWindow->setSettings(settings);
783 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
784 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
785 installWindow->show();
788 void RbUtilQt::uninstall(void)
790 if(chkConfig(true)) return;
791 UninstallWindow *uninstallWindow = new UninstallWindow(this);
792 uninstallWindow->setSettings(settings);
793 uninstallWindow->show();
797 void RbUtilQt::uninstallBootloader(void)
799 if(chkConfig(true)) return;
800 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
801 tr("Do you really want to uninstall the Bootloader?"),
802 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
803 // create logger
804 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
805 logger->show();
807 BootloaderInstaller blinstaller(this);
808 blinstaller.setMountPoint(settings->mountpoint());
809 blinstaller.setDevice(settings->curPlatform());
810 blinstaller.setBootloaderMethod(settings->curBootloaderMethod());
811 blinstaller.setBootloaderName(settings->curBootloaderName());
812 blinstaller.setBootloaderBaseUrl(settings->bootloaderUrl());
813 blinstaller.setBootloaderInfoUrl(settings->bootloaderInfoUrl());
814 if(!blinstaller.downloadInfo())
816 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
817 logger->abort();
818 return;
821 blinstaller.uninstall(logger);
826 void RbUtilQt::downloadManual(void)
828 if(chkConfig(true)) return;
829 if(QMessageBox::question(this, tr("Confirm download"),
830 tr("Do you really want to download the manual? The manual will be saved "
831 "to the root folder of your player."),
832 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
833 return;
835 buildInfo.open();
836 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
837 buildInfo.close();
839 QString manual = settings->curManual();
841 QString date = (info.value("dailies/date").toString());
843 QString manualurl;
844 QString target;
845 QString section;
846 if(ui.radioPdf->isChecked()) {
847 target = "/" + manual + ".pdf";
848 section = "Manual (PDF)";
850 else {
851 target = "/" + manual + "-" + date + "-html.zip";
852 section = "Manual (HTML)";
854 manualurl = settings->manualUrl() + "/" + target;
855 qDebug() << "manualurl =" << manualurl;
857 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
858 logger->show();
859 installer = new ZipInstaller(this);
860 installer->setMountPoint(settings->mountpoint());
861 if(!settings->cacheDisabled())
862 installer->setCache(true);
863 installer->setLogSection(section);
864 installer->setLogVersion(date);
865 installer->setUrl(manualurl);
866 installer->setUnzip(false);
867 installer->setTarget(target);
868 installer->install(logger);
872 void RbUtilQt::installPortable(void)
874 if(QMessageBox::question(this, tr("Confirm installation"),
875 tr("Do you really want to install Rockbox Utility to your player? "
876 "After installation you can run it from the players hard drive."),
877 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
878 return;
880 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
881 logger->setProgressMax(0);
882 logger->setProgressValue(0);
883 logger->show();
884 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
886 // check mountpoint
887 if(!QFileInfo(settings->mountpoint()).isDir()) {
888 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
889 logger->abort();
890 return;
893 // remove old files first.
894 QFile::remove(settings->mountpoint() + "/RockboxUtility.exe");
895 QFile::remove(settings->mountpoint() + "/RockboxUtility.ini");
896 // copy currently running binary and currently used settings file
897 if(!QFile::copy(qApp->applicationFilePath(), settings->mountpoint() + "/RockboxUtility.exe")) {
898 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
899 logger->abort();
900 return;
902 logger->addItem(tr("Installing user configuration"), LOGINFO);
903 if(!QFile::copy(settings->userSettingFilename(), settings->mountpoint() + "/RockboxUtility.ini")) {
904 logger->addItem(tr("Error installing user configuration"), LOGERROR);
905 logger->abort();
906 return;
908 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
909 logger->abort();
910 logger->setProgressMax(1);
911 logger->setProgressValue(1);
916 void RbUtilQt::updateInfo()
918 qDebug() << "RbUtilQt::updateInfo()";
920 QSettings log(settings->mountpoint() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
921 QStringList groups = log.childGroups();
922 QList<QTreeWidgetItem *> items;
923 QTreeWidgetItem *w, *w2;
924 QString min, max;
925 int olditems = 0;
927 // remove old list entries (if any)
928 int l = ui.treeInfo->topLevelItemCount();
929 while(l--) {
930 QTreeWidgetItem *m;
931 m = ui.treeInfo->takeTopLevelItem(l);
932 // delete childs (single level deep, no recursion here)
933 int n = m->childCount();
934 while(n--)
935 delete m->child(n);
937 // get and populate new items
938 for(int a = 0; a < groups.size(); a++) {
939 log.beginGroup(groups.at(a));
940 QStringList keys = log.allKeys();
941 w = new QTreeWidgetItem;
942 w->setFlags(Qt::ItemIsEnabled);
943 w->setText(0, groups.at(a));
944 items.append(w);
945 // get minimum and maximum version information so we can hilight old files
946 min = max = log.value(keys.at(0)).toString();
947 for(int b = 0; b < keys.size(); b++) {
948 if(log.value(keys.at(b)).toString() > max)
949 max = log.value(keys.at(b)).toString();
950 if(log.value(keys.at(b)).toString() < min)
951 min = log.value(keys.at(b)).toString();
954 for(int b = 0; b < keys.size(); b++) {
955 QString file;
956 file = settings->mountpoint() + "/" + keys.at(b);
957 if(QFileInfo(file).isDir())
958 continue;
959 w2 = new QTreeWidgetItem(w, QStringList() << "/"
960 + keys.at(b) << log.value(keys.at(b)).toString());
961 if(log.value(keys.at(b)).toString() != max) {
962 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
963 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
964 olditems++;
966 items.append(w2);
968 log.endGroup();
969 if(min != max)
970 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
971 else
972 w->setData(1, Qt::DisplayRole, max);
974 ui.treeInfo->insertTopLevelItems(0, items);
975 ui.treeInfo->resizeColumnToContents(0);
979 QUrl RbUtilQt::proxy()
981 if(settings->proxyType() == "manual")
982 return QUrl(settings->proxy());
983 else if(settings->proxy() == "system")
985 return systemProxy();
987 return QUrl("");
991 bool RbUtilQt::chkConfig(bool warn)
993 bool error = false;
994 if(settings->curPlatform().isEmpty()
995 || settings->mountpoint().isEmpty()
996 || !QFileInfo(settings->mountpoint()).isWritable()) {
997 error = true;
999 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1000 tr("Your configuration is invalid. Please go to the configuration "
1001 "dialog and make sure the selected values are correct."));
1003 return error;