Device detection based on USB PIDs. This is currently linux only and requires libusb...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob6a561e1b854726032260c561fdbac0bb92529b6e
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_Help, SIGNAL(triggered()), this, SLOT(help()));
85 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
86 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
87 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
88 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
89 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
90 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
91 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
92 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
93 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
94 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
95 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
96 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
97 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
98 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
100 #if !defined(STATIC)
101 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
102 #else
103 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
104 #endif
106 initIpodpatcher();
107 initSansapatcher();
108 downloadInfo();
113 void RbUtilQt::updateTabs(int count)
115 switch(count) {
116 case 6:
117 updateInfo();
118 break;
119 default:
120 break;
125 void RbUtilQt::downloadInfo()
127 // try to get the current build information
128 daily = new HttpGet(this);
129 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
130 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
131 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
132 daily->setProxy(proxy());
133 if(userSettings->value("offline").toBool())
134 daily->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
135 qDebug() << "downloading build info";
136 daily->setFile(&buildInfo);
137 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
141 void RbUtilQt::downloadDone(bool error)
143 if(error) {
144 qDebug() << "network error:" << daily->error();
145 return;
147 qDebug() << "network status:" << daily->error();
149 buildInfo.open();
150 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
151 buildInfo.close();
152 versmap.insert("arch_rev", info.value("dailies/rev").toString());
153 versmap.insert("arch_date", info.value("dailies/date").toString());
155 bleeding = new HttpGet(this);
156 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
157 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
158 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
159 bleeding->setProxy(proxy());
160 if(userSettings->value("offline").toBool())
161 bleeding->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
162 bleeding->setFile(&bleedingInfo);
163 bleeding->getFile(QUrl(devices->value("bleeding_info").toString()));
167 void RbUtilQt::downloadBleedingDone(bool error)
169 if(error) qDebug() << "network error:" << bleeding->error();
171 bleedingInfo.open();
172 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
173 bleedingInfo.close();
174 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
175 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
176 qDebug() << "versmap =" << versmap;
180 void RbUtilQt::downloadDone(int id, bool error)
182 QString errorString;
183 errorString = tr("Network error: %1. Please check your network and proxy settings.")
184 .arg(daily->errorString());
185 if(error) {
186 QMessageBox::about(this, "Network Error", errorString);
188 qDebug() << "downloadDone:" << id << error;
192 void RbUtilQt::about()
194 QDialog *window = new QDialog(this);
195 Ui::aboutBox about;
196 about.setupUi(window);
197 window->setModal(true);
199 QFile licence(":/docs/gpl-2.0.html");
200 licence.open(QIODevice::ReadOnly);
201 QTextStream c(&licence);
202 QString cline = c.readAll();
203 about.browserLicense->insertHtml(cline);
204 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
205 QFile credits(":/docs/CREDITS");
206 credits.open(QIODevice::ReadOnly);
207 QTextStream r(&credits);
208 QString rline = r.readAll();
209 about.browserCredits->insertPlainText(rline);
210 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
211 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
212 about.labelTitle->setText(title);
213 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
215 window->show();
220 void RbUtilQt::help()
222 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtilityQt");
223 QDesktopServices::openUrl(helpurl);
227 void RbUtilQt::configDialog()
229 Config *cw = new Config(this);
230 cw->setUserSettings(userSettings);
231 cw->setDevices(devices);
232 cw->show();
233 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
234 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
238 void RbUtilQt::updateSettings()
240 qDebug() << "updateSettings()";
241 updateDevice();
242 updateManual();
246 void RbUtilQt::updateDevice()
248 platform = userSettings->value("platform").toString();
249 // buttons
250 devices->beginGroup(platform);
251 if(devices->value("needsbootloader", "") == "no") {
252 ui.buttonBootloader->setEnabled(false);
253 ui.buttonRemoveBootloader->setEnabled(false);
254 ui.labelBootloader->setEnabled(false);
255 ui.labelRemoveBootloader->setEnabled(false);
257 else {
258 ui.buttonBootloader->setEnabled(true);
259 ui.labelBootloader->setEnabled(true);
260 if(devices->value("bootloadermethod") == "fwpatcher") {
261 ui.labelRemoveBootloader->setEnabled(false);
262 ui.buttonRemoveBootloader->setEnabled(false);
264 else {
265 ui.labelRemoveBootloader->setEnabled(true);
266 ui.buttonRemoveBootloader->setEnabled(true);
269 devices->endGroup();
270 // displayed device info
271 platform = userSettings->value("platform").toString();
272 QString mountpoint = userSettings->value("mountpoint").toString();
273 devices->beginGroup(platform);
274 QString brand = devices->value("brand").toString();
275 QString name = devices->value("name").toString();
276 devices->endGroup();
277 if(name.isEmpty()) name = "&lt;none&gt;";
278 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
279 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
280 .arg(brand, name, mountpoint));
284 void RbUtilQt::updateManual()
286 if(userSettings->value("platform").toString() != "")
288 devices->beginGroup(userSettings->value("platform").toString());
289 QString manual;
290 manual = devices->value("manualname", "").toString();
292 if(manual == "")
293 manual = "rockbox-" + devices->value("platform").toString();
294 devices->endGroup();
295 QString pdfmanual;
296 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
297 QString htmlmanual;
298 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
299 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
300 .arg(pdfmanual));
301 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
302 .arg(htmlmanual));
304 else {
305 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
306 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
307 .arg("http://www.rockbox.org/manual.shtml"));
312 void RbUtilQt::completeInstall()
314 if(QMessageBox::question(this, tr("Confirm Installation"),
315 tr("Do you really want to make a complete Installation?"),
316 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
318 // create logger
319 logger = new ProgressLoggerGui(this);
320 logger->show();
322 QString mountpoint = userSettings->value("mountpoint").toString();
323 // show dialog with error if mount point is wrong
324 if(!QFileInfo(mountpoint).isDir()) {
325 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
326 logger->abort();
327 return;
329 // Bootloader
330 m_error = false;
331 m_installed = false;
332 if(!installBootloaderAuto())
333 return;
334 else
336 // wait for boot loader installation finished
337 while(!m_installed)
338 QApplication::processEvents();
340 if(m_error) return;
341 logger->undoAbort();
343 // Rockbox
344 m_error = false;
345 m_installed = false;
346 if(!installAuto())
347 return;
348 else
350 // wait for boot loader installation finished
351 while(!m_installed)
352 QApplication::processEvents();
354 if(m_error) return;
355 logger->undoAbort();
357 // Fonts
358 m_error = false;
359 m_installed = false;
360 if(!installFontsAuto())
361 return;
362 else
364 // wait for boot loader installation finished
365 while(!m_installed)
366 QApplication::processEvents();
368 if(m_error) return;
369 logger->undoAbort();
371 // Doom
372 m_error = false;
373 m_installed = false;
374 if(!installDoomAuto())
375 return;
376 else
378 // wait for boot loader installation finished
379 while(!m_installed)
380 QApplication::processEvents();
382 if(m_error) return;
385 // theme
386 // this is a window
387 // it has its own logger window,so close our.
388 logger->close();
389 installThemes();
393 void RbUtilQt::smallInstall()
395 if(QMessageBox::question(this, tr("Confirm Installation"),
396 tr("Do you really want to make a small Installation?"),
397 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
399 // create logger
400 logger = new ProgressLoggerGui(this);
401 logger->show();
403 QString mountpoint = userSettings->value("mountpoint").toString();
404 // show dialog with error if mount point is wrong
405 if(!QFileInfo(mountpoint).isDir()) {
406 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
407 logger->abort();
408 return;
410 // Bootloader
411 m_error = false;
412 m_installed = false;
413 if(!installBootloaderAuto())
414 return;
415 else
417 // wait for boot loader installation finished
418 while(!m_installed)
419 QApplication::processEvents();
421 if(m_error) return;
422 logger->undoAbort();
424 // Rockbox
425 m_error = false;
426 m_installed = false;
427 if(!installAuto())
428 return;
429 else
431 // wait for boot loader installation finished
432 while(!m_installed)
433 QApplication::processEvents();
437 void RbUtilQt::installdone(bool error)
439 qDebug() << "install done";
440 m_installed = true;
441 m_error = error;
444 void RbUtilQt::installBtn()
446 install();
449 bool RbUtilQt::installAuto()
451 QString file = QString("%1%2/rockbox.zip")
452 .arg(devices->value("bleeding_url").toString(),
453 userSettings->value("platform").toString());
455 buildInfo.open();
456 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
457 buildInfo.close();
459 devices->beginGroup(platform);
460 QString released = devices->value("released").toString();
461 devices->endGroup();
462 if(released == "yes") {
463 // only set the keys if needed -- querying will yield an empty string
464 // if not set.
465 versmap.insert("rel_rev", devices->value("last_release").toString());
466 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
469 QString myversion = "r" + versmap.value("bleed_rev");
471 ZipInstaller* installer = new ZipInstaller(this);
472 installer->setUrl(file);
473 installer->setProxy(proxy());
474 installer->setLogSection("Rockbox (Base)");
475 installer->setLogVersion(myversion);
476 if(!userSettings->value("cachedisable").toBool())
477 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
478 installer->setMountPoint(userSettings->value("mountpoint").toString());
479 installer->install(logger);
481 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
483 return true;
486 void RbUtilQt::install()
488 Install *installWindow = new Install(this);
489 installWindow->setUserSettings(userSettings);
490 installWindow->setDeviceSettings(devices);
491 installWindow->setProxy(proxy());
493 buildInfo.open();
494 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
495 buildInfo.close();
497 devices->beginGroup(platform);
498 QString released = devices->value("released").toString();
499 devices->endGroup();
500 if(released == "yes") {
501 // only set the keys if needed -- querying will yield an empty string
502 // if not set.
503 versmap.insert("rel_rev", devices->value("last_release").toString());
504 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
506 installWindow->setVersionStrings(versmap);
508 installWindow->show();
511 bool RbUtilQt::installBootloaderAuto()
513 installBootloader();
514 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
515 return !m_error;
518 void RbUtilQt::installBootloaderBtn()
520 if(QMessageBox::question(this, tr("Confirm Installation"),
521 tr("Do you really want to install the Bootloader?"),
522 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
524 // create logger
525 logger = new ProgressLoggerGui(this);
526 logger->show();
528 installBootloader();
531 void RbUtilQt::installBootloader()
533 QString platform = userSettings->value("platform").toString();
535 // create installer
536 blinstaller = new BootloaderInstaller(this);
538 blinstaller->setMountPoint(userSettings->value("mountpoint").toString());
540 blinstaller->setProxy(proxy());
541 blinstaller->setDevice(platform);
542 blinstaller->setBootloaderMethod(devices->value(platform + "/bootloadermethod").toString());
543 blinstaller->setBootloaderName(devices->value(platform + "/bootloadername").toString());
544 blinstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
545 blinstaller->setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
546 if(!blinstaller->downloadInfo())
548 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
549 logger->abort();
550 m_error = true;
551 return;
554 if(blinstaller->uptodate())
556 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
557 tr("It seem your Bootloader is already uptodate.\n"
558 "Do really want to install it?"),
559 QMessageBox::Ok | QMessageBox::Ignore |QMessageBox::Cancel,
560 QMessageBox::Cancel);
561 if(ret == QMessageBox::Cancel)
563 logger->addItem(tr("Bootloader installation Canceled!"),LOGERROR);
564 logger->abort();
565 m_error = true;
566 return;
568 else if(ret == QMessageBox::Ignore)
570 logger->addItem(tr("Bootloader installation Skipped!"),LOGERROR);
571 logger->abort();
572 m_installed = true;
573 return;
577 // if fwpatcher , ask for extra file
578 QString offirmware;
579 if(devices->value(platform + "/bootloadermethod").toString() == "fwpatcher")
581 BrowseOF ofbrowser(this);
582 ofbrowser.setFile(userSettings->value("ofpath").toString());
583 if(ofbrowser.exec() == QDialog::Accepted)
585 offirmware = ofbrowser.getFile();
586 qDebug() << offirmware;
587 if(!QFileInfo(offirmware).exists())
589 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
590 logger->abort();
591 m_error = true;
592 return;
594 else
596 userSettings->setValue("ofpath",offirmware);
597 userSettings->sync();
600 else
602 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
603 logger->abort();
604 m_error = true;
605 return;
608 blinstaller->setOrigFirmwarePath(offirmware);
610 blinstaller->install(logger);
613 void RbUtilQt::installFontsBtn()
615 if(QMessageBox::question(this, tr("Confirm Installation"),
616 tr("Do you really want to install the fonts package?"),
617 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
618 // create logger
619 logger = new ProgressLoggerGui(this);
620 logger->show();
621 installFonts();
624 bool RbUtilQt::installFontsAuto()
626 installFonts();
627 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
628 return !m_error;
631 void RbUtilQt::installFonts()
633 // create zip installer
634 installer = new ZipInstaller(this);
636 installer->setUrl(devices->value("font_url").toString());
637 installer->setProxy(proxy());
638 installer->setLogSection("Fonts");
639 installer->setLogVersion(versmap.value("arch_date"));
640 installer->setMountPoint(userSettings->value("mountpoint").toString());
641 if(!userSettings->value("cachedisable").toBool())
642 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
643 installer->install(logger);
647 void RbUtilQt::installVoice()
649 if(QMessageBox::question(this, tr("Confirm Installation"),
650 tr("Do you really want to install the voice file?"),
651 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
652 // create logger
653 logger = new ProgressLoggerGui(this);
654 logger->show();
656 // create zip installer
657 installer = new ZipInstaller(this);
658 installer->setUnzip(false);
660 QString voiceurl = devices->value("voice_url").toString() + "/" +
661 userSettings->value("platform").toString() + "-" +
662 versmap.value("arch_date") + "-english.voice";
663 qDebug() << voiceurl;
665 installer->setProxy(proxy());
666 installer->setUrl(voiceurl);
667 installer->setLogSection("Voice");
668 installer->setLogVersion(versmap.value("arch_date"));
669 installer->setMountPoint(userSettings->value("mountpoint").toString());
670 installer->setTarget("/.rockbox/langs/english.voice");
671 if(!userSettings->value("cachedisable").toBool())
672 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
673 installer->install(logger);
675 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
678 void RbUtilQt::installDoomBtn()
680 QFile doomrock(userSettings->value("mountpoint").toString()+"/.rockbox/rocks/games/doom.rock");
681 if(!doomrock.exists()){
682 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
683 return;
686 if(QMessageBox::question(this, tr("Confirm Installation"),
687 tr("Do you really want to install the game addon files?"),
688 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
689 // create logger
690 logger = new ProgressLoggerGui(this);
691 logger->show();
693 installDoom();
695 bool RbUtilQt::installDoomAuto()
697 installDoom();
698 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
699 return !m_error;
702 void RbUtilQt::installDoom()
704 // create zip installer
705 installer = new ZipInstaller(this);
707 installer->setUrl(devices->value("doom_url").toString());
708 installer->setProxy(proxy());
709 installer->setLogSection("Game Addons");
710 installer->setLogVersion(versmap.value("arch_date"));
711 installer->setMountPoint(userSettings->value("mountpoint").toString());
712 if(!userSettings->value("cachedisable").toBool())
713 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
714 installer->install(logger);
719 void RbUtilQt::installThemes()
721 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
722 tw->setDeviceSettings(devices);
723 tw->setUserSettings(userSettings);
724 tw->setProxy(proxy());
725 tw->setModal(true);
726 tw->show();
730 void RbUtilQt::createTalkFiles(void)
732 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
733 installWindow->setUserSettings(userSettings);
734 installWindow->setDeviceSettings(devices);
735 installWindow->show();
739 void RbUtilQt::uninstall(void)
741 UninstallWindow *uninstallWindow = new UninstallWindow(this);
742 uninstallWindow->setUserSettings(userSettings);
743 uninstallWindow->setDeviceSettings(devices);
744 uninstallWindow->show();
747 void RbUtilQt::uninstallBootloader(void)
749 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
750 tr("Do you really want to uninstall the Bootloader?"),
751 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
752 // create logger
753 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
754 logger->show();
756 QString plattform = userSettings->value("platform").toString();
757 BootloaderInstaller blinstaller(this);
758 blinstaller.setMountPoint(userSettings->value("mountpoint").toString());
759 blinstaller.setDevice(userSettings->value("platform").toString());
760 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
761 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
762 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
763 blinstaller.setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
764 if(!blinstaller.downloadInfo())
766 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
767 logger->abort();
768 return;
771 blinstaller.uninstall(logger);
776 void RbUtilQt::downloadManual(void)
778 if(QMessageBox::question(this, tr("Confirm download"),
779 tr("Do you really want to download the manual? The manual will be saved "
780 "to the root folder of your player."),
781 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
782 return;
784 buildInfo.open();
785 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
786 buildInfo.close();
788 devices->beginGroup(userSettings->value("platform").toString());
789 QString manual;
790 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
791 devices->endGroup();
793 QString date = (info.value("dailies/date").toString());
795 QString manualurl;
796 QString target;
797 QString section;
798 if(ui.radioPdf->isChecked()) {
799 target = "/" + manual + ".pdf";
800 section = "Manual (PDF)";
802 else {
803 target = "/" + manual + "-" + date + "-html.zip";
804 section = "Manual (HTML)";
806 manualurl = devices->value("manual_url").toString() + "/" + target;
807 qDebug() << "manualurl =" << manualurl;
809 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
810 logger->show();
811 installer = new ZipInstaller(this);
812 installer->setMountPoint(userSettings->value("mountpoint").toString());
813 if(!userSettings->value("cachedisable").toBool())
814 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
815 installer->setProxy(proxy());
816 installer->setLogSection(section);
817 installer->setUrl(manualurl);
818 installer->setUnzip(false);
819 installer->setTarget(target);
820 installer->install(logger);
824 void RbUtilQt::installPortable(void)
826 if(QMessageBox::question(this, tr("Confirm installation"),
827 tr("Do you really want to install Rockbox Utility to your player? "
828 "After installation you can run it from the players hard drive."),
829 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
830 return;
832 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
833 logger->show();
834 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
836 // check mountpoint
837 if(!QFileInfo(userSettings->value("mountpoint").toString()).isDir()) {
838 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
839 logger->abort();
840 return;
843 // remove old files first.
844 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.exe");
845 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.ini");
846 // copy currently running binary and currently used settings file
847 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("mountpoint").toString() + "/RockboxUtility.exe")) {
848 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
849 logger->abort();
850 return;
852 logger->addItem(tr("Installing user configuration"), LOGINFO);
853 if(!QFile::copy(userSettings->fileName(), userSettings->value("mountpoint").toString() + "/RockboxUtility.ini")) {
854 logger->addItem(tr("Error installing user configuration"), LOGERROR);
855 logger->abort();
856 return;
858 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
859 logger->abort();
864 void RbUtilQt::updateInfo()
866 qDebug() << "RbUtilQt::updateInfo()";
868 QSettings log(userSettings->value("mountpoint").toString() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
869 QStringList groups = log.childGroups();
870 QList<QTreeWidgetItem *> items;
871 QTreeWidgetItem *w, *w2;
872 QString min, max;
873 int olditems = 0;
875 // remove old list entries (if any)
876 int l = ui.treeInfo->topLevelItemCount();
877 while(l--) {
878 QTreeWidgetItem *m;
879 m = ui.treeInfo->takeTopLevelItem(l);
880 // delete childs (single level deep, no recursion here)
881 int n = m->childCount();
882 while(n--)
883 delete m->child(n);
885 // get and populate new items
886 for(int a = 0; a < groups.size(); a++) {
887 log.beginGroup(groups.at(a));
888 QStringList keys = log.allKeys();
889 w = new QTreeWidgetItem;
890 w->setFlags(Qt::ItemIsEnabled);
891 w->setText(0, groups.at(a));
892 items.append(w);
893 // get minimum and maximum version information so we can hilight old files
894 min = max = log.value(keys.at(0)).toString();
895 for(int b = 0; b < keys.size(); b++) {
896 if(log.value(keys.at(b)).toString() > max)
897 max = log.value(keys.at(b)).toString();
898 if(log.value(keys.at(b)).toString() < min)
899 min = log.value(keys.at(b)).toString();
902 for(int b = 0; b < keys.size(); b++) {
903 QString file;
904 file = userSettings->value("mountpoint").toString() + "/" + keys.at(b);
905 if(QFileInfo(file).isDir())
906 continue;
907 w2 = new QTreeWidgetItem(w, QStringList() << "/"
908 + keys.at(b) << log.value(keys.at(b)).toString());
909 if(log.value(keys.at(b)).toString() != max) {
910 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
911 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
912 olditems++;
914 items.append(w2);
916 log.endGroup();
917 if(min != max)
918 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
919 else
920 w->setData(1, Qt::DisplayRole, max);
922 ui.treeInfo->insertTopLevelItems(0, items);
923 ui.treeInfo->resizeColumnToContents(0);
927 QUrl RbUtilQt::proxy()
929 if(userSettings->value("proxytype") == "manual")
930 return QUrl(userSettings->value("proxy").toString());
931 #ifdef __linux
932 else if(userSettings->value("proxytype") == "system")
933 return QUrl(getenv("http_proxy"));
934 #endif
935 return QUrl("");