Implement download caching. Set the folder for the cache data in the configuration...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob5f96a592c1c43ad19117808bce9c631c0fd4300f
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 "httpget.h"
30 #include "installbootloader.h"
31 #include "installthemes.h"
32 #include "uninstallwindow.h"
33 #include "browseof.h"
35 #ifdef __linux
36 #include <stdio.h>
37 #endif
39 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
41 absolutePath = qApp->applicationDirPath();
42 // use built-in rbutil.ini if no external file in binary folder
43 QString iniFile = absolutePath + "/rbutil.ini";
44 if(QFileInfo(iniFile).isFile()) {
45 qDebug() << "using external rbutil.ini";
46 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
48 else {
49 qDebug() << "using built-in rbutil.ini";
50 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
53 ui.setupUi(this);
55 // portable installation:
56 // check for a configuration file in the program folder.
57 QFileInfo config;
58 config.setFile(absolutePath + "/RockboxUtility.ini");
59 if(config.isFile()) {
60 userSettings = new QSettings(absolutePath + "/RockboxUtility.ini",
61 QSettings::IniFormat, 0);
62 qDebug() << "config: portable";
64 else {
65 userSettings = new QSettings(QSettings::IniFormat,
66 QSettings::UserScope, "rockbox.org", "RockboxUtility");
67 qDebug() << "config: system";
70 // manual tab
71 updateManual();
72 updateDevice();
73 ui.radioPdf->setChecked(true);
75 // info tab
76 ui.treeInfo->setAlternatingRowColors(true);
77 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
78 ui.treeInfo->expandAll();
79 ui.treeInfo->setColumnCount(2);
81 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
82 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
83 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
84 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
85 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
86 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
87 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
88 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
89 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
90 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
91 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
92 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
93 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
94 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
95 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
96 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
97 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
99 #if !defined(STATIC)
100 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
101 #else
102 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
103 #endif
105 initIpodpatcher();
106 initSansapatcher();
107 downloadInfo();
112 void RbUtilQt::updateTabs(int count)
114 switch(count) {
115 case 6:
116 updateInfo();
117 break;
118 default:
119 break;
124 void RbUtilQt::downloadInfo()
126 // try to get the current build information
127 daily = new HttpGet(this);
128 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
129 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
130 daily->setProxy(proxy());
131 if(userSettings->value("defaults/offline").toBool())
132 daily->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
133 qDebug() << "downloading build info";
134 daily->setFile(&buildInfo);
135 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
139 void RbUtilQt::downloadDone(bool error)
141 if(error) {
142 qDebug() << "network error:" << daily->error();
143 return;
145 qDebug() << "network status:" << daily->error();
147 buildInfo.open();
148 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
149 buildInfo.close();
150 versmap.insert("arch_rev", info.value("dailies/rev").toString());
151 versmap.insert("arch_date", info.value("dailies/date").toString());
153 bleeding = new HttpGet(this);
154 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
155 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
156 bleeding->setProxy(proxy());
157 if(userSettings->value("defaults/offline").toBool())
158 bleeding->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
159 bleeding->setFile(&bleedingInfo);
160 bleeding->getFile(QUrl(devices->value("bleeding_info").toString()));
164 void RbUtilQt::downloadBleedingDone(bool error)
166 if(error) qDebug() << "network error:" << bleeding->error();
168 bleedingInfo.open();
169 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
170 bleedingInfo.close();
171 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
172 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
173 qDebug() << "versmap =" << versmap;
177 void RbUtilQt::downloadDone(int id, bool error)
179 QString errorString;
180 errorString = tr("Network error: %1. Please check your network and proxy settings.")
181 .arg(daily->errorString());
182 if(error) {
183 QMessageBox::about(this, "Network Error", errorString);
185 qDebug() << "downloadDone:" << id << error;
189 void RbUtilQt::about()
191 QDialog *window = new QDialog(this);
192 Ui::aboutBox about;
193 about.setupUi(window);
194 window->setModal(true);
196 QFile licence(":/docs/gpl-2.0.html");
197 licence.open(QIODevice::ReadOnly);
198 QTextStream c(&licence);
199 QString cline = c.readAll();
200 about.browserLicense->insertHtml(cline);
201 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
202 QFile credits(":/docs/CREDITS");
203 credits.open(QIODevice::ReadOnly);
204 QTextStream r(&credits);
205 QString rline = r.readAll();
206 about.browserCredits->insertPlainText(rline);
207 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
208 QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
209 about.labelTitle->setText(title);
210 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
212 window->show();
217 void RbUtilQt::configDialog()
219 Config *cw = new Config(this);
220 cw->setUserSettings(userSettings);
221 cw->setDevices(devices);
222 cw->show();
223 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
224 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
228 void RbUtilQt::updateSettings()
230 qDebug() << "updateSettings()";
231 updateDevice();
232 updateManual();
236 void RbUtilQt::updateDevice()
238 platform = userSettings->value("defaults/platform").toString();
239 // buttons
240 devices->beginGroup(platform);
241 if(devices->value("needsbootloader", "") == "no") {
242 ui.buttonBootloader->setEnabled(false);
243 ui.buttonRemoveBootloader->setEnabled(false);
244 ui.labelBootloader->setEnabled(false);
245 ui.labelRemoveBootloader->setEnabled(false);
247 else {
248 ui.buttonBootloader->setEnabled(true);
249 ui.labelBootloader->setEnabled(true);
250 if(devices->value("bootloadermethod") == "fwpatcher") {
251 ui.labelRemoveBootloader->setEnabled(false);
252 ui.buttonRemoveBootloader->setEnabled(false);
254 else {
255 ui.labelRemoveBootloader->setEnabled(true);
256 ui.buttonRemoveBootloader->setEnabled(true);
259 devices->endGroup();
260 // displayed device info
261 platform = userSettings->value("defaults/platform").toString();
262 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
263 devices->beginGroup(platform);
264 QString brand = devices->value("brand").toString();
265 QString name = devices->value("name").toString();
266 devices->endGroup();
267 if(name.isEmpty()) name = "&lt;none&gt;";
268 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
269 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
270 .arg(brand, name, mountpoint));
274 void RbUtilQt::updateManual()
276 if(userSettings->value("defaults/platform").toString() != "")
278 devices->beginGroup(userSettings->value("defaults/platform").toString());
279 QString manual;
280 manual = devices->value("manualname", "").toString();
282 if(manual == "")
283 manual = "rockbox-" + devices->value("platform").toString();
284 devices->endGroup();
285 QString pdfmanual;
286 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
287 QString htmlmanual;
288 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
289 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
290 .arg(pdfmanual));
291 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
292 .arg(htmlmanual));
294 else {
295 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
296 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
297 .arg("http://www.rockbox.org/manual.shtml"));
302 void RbUtilQt::completeInstall()
304 if(QMessageBox::question(this, tr("Confirm Installation"),
305 tr("Do you really want to make a complete Installation?"),
306 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
308 // create logger
309 logger = new ProgressLoggerGui(this);
310 logger->show();
312 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
313 // show dialog with error if mount point is wrong
314 if(!QFileInfo(mountpoint).isDir()) {
315 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
316 logger->abort();
317 return;
319 // Bootloader
320 m_error = false;
321 m_installed = false;
322 if(!installBootloaderAuto())
323 return;
324 else
326 // wait for boot loader installation finished
327 while(!m_installed)
328 QApplication::processEvents();
330 if(m_error) return;
331 logger->undoAbort();
333 // Rockbox
334 m_error = false;
335 m_installed = false;
336 if(!installAuto())
337 return;
338 else
340 // wait for boot loader installation finished
341 while(!m_installed)
342 QApplication::processEvents();
344 if(m_error) return;
345 logger->undoAbort();
347 // Fonts
348 m_error = false;
349 m_installed = false;
350 if(!installFontsAuto())
351 return;
352 else
354 // wait for boot loader installation finished
355 while(!m_installed)
356 QApplication::processEvents();
358 if(m_error) return;
359 logger->undoAbort();
361 // Doom
362 m_error = false;
363 m_installed = false;
364 if(!installDoomAuto())
365 return;
366 else
368 // wait for boot loader installation finished
369 while(!m_installed)
370 QApplication::processEvents();
372 if(m_error) return;
375 // theme
376 // this is a window
377 // it has its own logger window,so close our.
378 logger->close();
379 installThemes();
383 void RbUtilQt::smallInstall()
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 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
394 // show dialog with error if mount point is wrong
395 if(!QFileInfo(mountpoint).isDir()) {
396 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
397 logger->abort();
398 return;
400 // Bootloader
401 m_error = false;
402 m_installed = false;
403 if(!installBootloaderAuto())
404 return;
405 else
407 // wait for boot loader installation finished
408 while(!m_installed)
409 QApplication::processEvents();
411 if(m_error) return;
412 logger->undoAbort();
414 // Rockbox
415 m_error = false;
416 m_installed = false;
417 if(!installAuto())
418 return;
419 else
421 // wait for boot loader installation finished
422 while(!m_installed)
423 QApplication::processEvents();
427 void RbUtilQt::installdone(bool error)
429 qDebug() << "install done";
430 m_installed = true;
431 m_error = error;
434 void RbUtilQt::installBtn()
436 install();
439 bool RbUtilQt::installAuto()
441 QString file = QString("%1%2/rockbox.zip")
442 .arg(devices->value("bleeding_url").toString(),
443 userSettings->value("defaults/platform").toString());
445 buildInfo.open();
446 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
447 buildInfo.close();
449 devices->beginGroup(platform);
450 QString released = devices->value("released").toString();
451 devices->endGroup();
452 if(released == "yes") {
453 // only set the keys if needed -- querying will yield an empty string
454 // if not set.
455 versmap.insert("rel_rev", devices->value("last_release").toString());
456 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
459 QString myversion = "r" + versmap.value("bleed_rev");
461 ZipInstaller* installer = new ZipInstaller(this);
462 installer->setUrl(file);
463 installer->setProxy(proxy());
464 installer->setLogSection("rockboxbase");
465 installer->setLogVersion(myversion);
466 if(!userSettings->value("defaults/cachedisable").toBool())
467 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
468 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
469 installer->install(logger);
471 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
473 return true;
476 void RbUtilQt::install()
478 Install *installWindow = new Install(this);
479 installWindow->setUserSettings(userSettings);
480 installWindow->setDeviceSettings(devices);
481 installWindow->setProxy(proxy());
483 buildInfo.open();
484 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
485 buildInfo.close();
487 devices->beginGroup(platform);
488 QString released = devices->value("released").toString();
489 devices->endGroup();
490 if(released == "yes") {
491 // only set the keys if needed -- querying will yield an empty string
492 // if not set.
493 versmap.insert("rel_rev", devices->value("last_release").toString());
494 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
496 installWindow->setVersionStrings(versmap);
498 installWindow->show();
501 bool RbUtilQt::installBootloaderAuto()
503 installBootloader();
504 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
505 return !m_error;
508 void RbUtilQt::installBootloaderBtn()
510 if(QMessageBox::question(this, tr("Confirm Installation"),
511 tr("Do you really want to install the Bootloader?"),
512 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
514 // create logger
515 logger = new ProgressLoggerGui(this);
516 logger->show();
518 installBootloader();
521 void RbUtilQt::installBootloader()
523 QString platform = userSettings->value("defaults/platform").toString();
525 // create installer
526 blinstaller = new BootloaderInstaller(this);
528 blinstaller->setMountPoint(userSettings->value("defaults/mountpoint").toString());
530 blinstaller->setProxy(proxy());
531 blinstaller->setDevice(platform);
532 blinstaller->setBootloaderMethod(devices->value(platform + "/bootloadermethod").toString());
533 blinstaller->setBootloaderName(devices->value(platform + "/bootloadername").toString());
534 blinstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
535 blinstaller->setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
536 if(!blinstaller->downloadInfo())
538 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
539 logger->abort();
540 m_error = true;
541 return;
544 if(blinstaller->uptodate())
546 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
547 tr("It seem your Bootloader is already uptodate.\n"
548 "Do really want to install it?"),
549 QMessageBox::Ok | QMessageBox::Ignore |QMessageBox::Cancel,
550 QMessageBox::Cancel);
551 if(ret == QMessageBox::Cancel)
553 logger->addItem(tr("Bootloader installation Canceled!"),LOGERROR);
554 logger->abort();
555 m_error = true;
556 return;
558 else if(ret == QMessageBox::Ignore)
560 m_installed = true;
561 return;
565 // if fwpatcher , ask for extra file
566 QString offirmware;
567 if(devices->value(platform + "/bootloadermethod").toString() == "fwpatcher")
569 BrowseOF ofbrowser(this);
570 ofbrowser.setFile(userSettings->value("defaults/ofpath").toString());
571 if(ofbrowser.exec() == QDialog::Accepted)
573 offirmware = ofbrowser.getFile();
574 qDebug() << offirmware;
575 if(!QFileInfo(offirmware).exists())
577 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
578 logger->abort();
579 m_error = true;
580 return;
582 else
584 userSettings->setValue("defaults/ofpath",offirmware);
585 userSettings->sync();
588 else
590 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
591 logger->abort();
592 m_error = true;
593 return;
596 blinstaller->setOrigFirmwarePath(offirmware);
598 blinstaller->install(logger);
601 void RbUtilQt::installFontsBtn()
603 if(QMessageBox::question(this, tr("Confirm Installation"),
604 tr("Do you really want to install the fonts package?"),
605 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
606 // create logger
607 logger = new ProgressLoggerGui(this);
608 logger->show();
609 installFonts();
612 bool RbUtilQt::installFontsAuto()
614 installFonts();
615 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
616 return !m_error;
619 void RbUtilQt::installFonts()
621 // create zip installer
622 installer = new ZipInstaller(this);
624 installer->setUrl(devices->value("font_url").toString());
625 installer->setProxy(proxy());
626 installer->setLogSection("Fonts");
627 installer->setLogVersion(versmap.value("arch_date"));
628 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
629 if(!userSettings->value("defaults/cachedisable").toBool())
630 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
631 installer->install(logger);
635 void RbUtilQt::installVoice()
637 if(QMessageBox::question(this, tr("Confirm Installation"),
638 tr("Do you really want to install the voice file?"),
639 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
640 // create logger
641 logger = new ProgressLoggerGui(this);
642 logger->show();
644 // create zip installer
645 installer = new ZipInstaller(this);
646 installer->setUnzip(false);
648 QString voiceurl = devices->value("voice_url").toString() + "/" +
649 userSettings->value("defaults/platform").toString() + "-" +
650 versmap.value("arch_date") + "-english.voice";
651 qDebug() << voiceurl;
653 installer->setProxy(proxy());
654 installer->setUrl(voiceurl);
655 installer->setLogSection("Voice");
656 installer->setLogVersion(versmap.value("arch_date"));
657 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
658 installer->setTarget("/.rockbox/langs/english.voice");
659 if(!userSettings->value("defaults/cachedisable").toBool())
660 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
661 installer->install(logger);
663 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
666 void RbUtilQt::installDoomBtn()
668 if(QMessageBox::question(this, tr("Confirm Installation"),
669 tr("Do you really want to install the game addon files?"),
670 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
671 // create logger
672 logger = new ProgressLoggerGui(this);
673 logger->show();
675 installDoom();
677 bool RbUtilQt::installDoomAuto()
679 installDoom();
680 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
681 return !m_error;
684 void RbUtilQt::installDoom()
686 // create zip installer
687 installer = new ZipInstaller(this);
689 installer->setUrl(devices->value("doom_url").toString());
690 installer->setProxy(proxy());
691 installer->setLogSection("Game Addons");
692 installer->setLogVersion(versmap.value("arch_date"));
693 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
694 if(!userSettings->value("defaults/cachedisable").toBool())
695 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
696 installer->install(logger);
701 void RbUtilQt::installThemes()
703 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
704 tw->setDeviceSettings(devices);
705 tw->setUserSettings(userSettings);
706 tw->setProxy(proxy());
707 tw->setModal(true);
708 tw->show();
712 void RbUtilQt::createTalkFiles(void)
714 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
715 installWindow->setUserSettings(userSettings);
716 installWindow->setDeviceSettings(devices);
717 installWindow->show();
721 void RbUtilQt::uninstall(void)
723 UninstallWindow *uninstallWindow = new UninstallWindow(this);
724 uninstallWindow->setUserSettings(userSettings);
725 uninstallWindow->setDeviceSettings(devices);
726 uninstallWindow->show();
729 void RbUtilQt::uninstallBootloader(void)
731 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
732 tr("Do you really want to uninstall the Bootloader?"),
733 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
734 // create logger
735 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
736 logger->show();
738 QString plattform = userSettings->value("defaults/platform").toString();
739 BootloaderInstaller blinstaller(this);
740 blinstaller.setMountPoint(userSettings->value("defaults/mountpoint").toString());
741 blinstaller.setDevice(userSettings->value("defaults/platform").toString());
742 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
743 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
744 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
745 blinstaller.setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
746 if(!blinstaller.downloadInfo())
748 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
749 logger->abort();
750 return;
753 blinstaller.uninstall(logger);
758 void RbUtilQt::downloadManual(void)
760 if(QMessageBox::question(this, tr("Confirm download"),
761 tr("Do you really want to download the manual? The manual will be saved "
762 "to the root folder of your player."),
763 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
764 return;
766 buildInfo.open();
767 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
768 buildInfo.close();
770 devices->beginGroup(userSettings->value("defaults/platform").toString());
771 QString manual;
772 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
773 devices->endGroup();
775 QString date = (info.value("dailies/date").toString());
777 QString manualurl;
778 QString target;
779 QString section;
780 if(ui.radioPdf->isChecked()) {
781 target = "/" + manual + ".pdf";
782 section = "Manual (PDF)";
784 else {
785 target = "/" + manual + "-" + date + "-html.zip";
786 section = "Manual (HTML)";
788 manualurl = devices->value("manual_url").toString() + "/" + target;
789 qDebug() << "manualurl =" << manualurl;
791 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
792 logger->show();
793 installer = new ZipInstaller(this);
794 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
795 if(!userSettings->value("defaults/cachedisable").toBool())
796 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
797 installer->setProxy(proxy());
798 installer->setLogSection(section);
799 installer->setUrl(manualurl);
800 installer->setUnzip(false);
801 installer->setTarget(target);
802 installer->install(logger);
806 void RbUtilQt::installPortable(void)
808 if(QMessageBox::question(this, tr("Confirm installation"),
809 tr("Do you really want to install Rockbox Utility to your player? "
810 "After installation you can run it from the players hard drive."),
811 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
812 return;
814 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
815 logger->show();
816 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
818 // check mountpoint
819 if(!QFileInfo(userSettings->value("defaults/mountpoint").toString()).isDir()) {
820 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
821 logger->abort();
822 return;
825 // remove old files first.
826 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.exe");
827 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.ini");
828 // copy currently running binary and currently used settings file
829 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.exe")) {
830 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
831 logger->abort();
832 return;
834 logger->addItem(tr("Installing user configuration"), LOGINFO);
835 if(!QFile::copy(userSettings->fileName(), userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.ini")) {
836 logger->addItem(tr("Error installing user configuration"), LOGERROR);
837 logger->abort();
838 return;
840 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
841 logger->abort();
846 void RbUtilQt::updateInfo()
848 qDebug() << "RbUtilQt::updateInfo()";
850 QSettings log(userSettings->value("defaults/mountpoint").toString() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
851 QStringList groups = log.childGroups();
852 QList<QTreeWidgetItem *> items;
853 QTreeWidgetItem *w, *w2;
854 QString min, max;
855 int olditems = 0;
857 // remove old list entries (if any)
858 int l = ui.treeInfo->topLevelItemCount();
859 while(l--) {
860 QTreeWidgetItem *m;
861 m = ui.treeInfo->takeTopLevelItem(l);
862 // delete childs (single level deep, no recursion here)
863 int n = m->childCount();
864 while(n--)
865 delete m->child(n);
867 // get and populate new items
868 for(int a = 0; a < groups.size(); a++) {
869 log.beginGroup(groups.at(a));
870 QStringList keys = log.allKeys();
871 w = new QTreeWidgetItem;
872 w->setFlags(Qt::ItemIsEnabled);
873 w->setText(0, groups.at(a));
874 items.append(w);
875 // get minimum and maximum version information so we can hilight old files
876 min = max = log.value(keys.at(0)).toString();
877 for(int b = 0; b < keys.size(); b++) {
878 if(log.value(keys.at(b)).toString() > max)
879 max = log.value(keys.at(b)).toString();
880 if(log.value(keys.at(b)).toString() < min)
881 min = log.value(keys.at(b)).toString();
884 for(int b = 0; b < keys.size(); b++) {
885 QString file;
886 file = userSettings->value("defaults/mountpoint").toString() + "/" + keys.at(b);
887 if(QFileInfo(file).isDir())
888 continue;
889 w2 = new QTreeWidgetItem(w, QStringList() << "/"
890 + keys.at(b) << log.value(keys.at(b)).toString());
891 if(log.value(keys.at(b)).toString() != max) {
892 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
893 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
894 olditems++;
896 items.append(w2);
898 log.endGroup();
899 if(min != max)
900 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
901 else
902 w->setData(1, Qt::DisplayRole, max);
904 ui.treeInfo->insertTopLevelItems(0, items);
905 ui.treeInfo->resizeColumnToContents(0);
909 QUrl RbUtilQt::proxy()
911 if(userSettings->value("defaults/proxytype") == "manual")
912 return QUrl(userSettings->value("defaults/proxy").toString());
913 #ifdef __linux
914 else if(userSettings->value("defaults/proxytype") == "system")
915 return QUrl(getenv("http_proxy"));
916 #endif
917 return QUrl("");