make sure closing the application aborts the remaining HttpGet objects. Should fix...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blobb3bd36bd254fb762a7c049dc274bf77c744b1f38
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("defaults/offline").toBool())
134 daily->setCache(userSettings->value("defaults/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("defaults/offline").toBool())
161 bleeding->setCache(userSettings->value("defaults/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("defaults/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("defaults/platform").toString();
272 QString mountpoint = userSettings->value("defaults/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("defaults/platform").toString() != "")
288 devices->beginGroup(userSettings->value("defaults/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("defaults/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("defaults/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("defaults/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("defaults/cachedisable").toBool())
477 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
478 installer->setMountPoint(userSettings->value("defaults/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("defaults/platform").toString();
535 // create installer
536 blinstaller = new BootloaderInstaller(this);
538 blinstaller->setMountPoint(userSettings->value("defaults/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("defaults/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("defaults/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("defaults/mountpoint").toString());
641 if(!userSettings->value("defaults/cachedisable").toBool())
642 installer->setCache(userSettings->value("defaults/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("defaults/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("defaults/mountpoint").toString());
670 installer->setTarget("/.rockbox/langs/english.voice");
671 if(!userSettings->value("defaults/cachedisable").toBool())
672 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
673 installer->install(logger);
675 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
678 void RbUtilQt::installDoomBtn()
680 if(QMessageBox::question(this, tr("Confirm Installation"),
681 tr("Do you really want to install the game addon files?"),
682 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
683 // create logger
684 logger = new ProgressLoggerGui(this);
685 logger->show();
687 installDoom();
689 bool RbUtilQt::installDoomAuto()
691 installDoom();
692 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
693 return !m_error;
696 void RbUtilQt::installDoom()
698 // create zip installer
699 installer = new ZipInstaller(this);
701 installer->setUrl(devices->value("doom_url").toString());
702 installer->setProxy(proxy());
703 installer->setLogSection("Game Addons");
704 installer->setLogVersion(versmap.value("arch_date"));
705 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
706 if(!userSettings->value("defaults/cachedisable").toBool())
707 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
708 installer->install(logger);
713 void RbUtilQt::installThemes()
715 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
716 tw->setDeviceSettings(devices);
717 tw->setUserSettings(userSettings);
718 tw->setProxy(proxy());
719 tw->setModal(true);
720 tw->show();
724 void RbUtilQt::createTalkFiles(void)
726 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
727 installWindow->setUserSettings(userSettings);
728 installWindow->setDeviceSettings(devices);
729 installWindow->show();
733 void RbUtilQt::uninstall(void)
735 UninstallWindow *uninstallWindow = new UninstallWindow(this);
736 uninstallWindow->setUserSettings(userSettings);
737 uninstallWindow->setDeviceSettings(devices);
738 uninstallWindow->show();
741 void RbUtilQt::uninstallBootloader(void)
743 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
744 tr("Do you really want to uninstall the Bootloader?"),
745 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
746 // create logger
747 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
748 logger->show();
750 QString plattform = userSettings->value("defaults/platform").toString();
751 BootloaderInstaller blinstaller(this);
752 blinstaller.setMountPoint(userSettings->value("defaults/mountpoint").toString());
753 blinstaller.setDevice(userSettings->value("defaults/platform").toString());
754 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
755 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
756 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
757 blinstaller.setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
758 if(!blinstaller.downloadInfo())
760 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
761 logger->abort();
762 return;
765 blinstaller.uninstall(logger);
770 void RbUtilQt::downloadManual(void)
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 devices->beginGroup(userSettings->value("defaults/platform").toString());
783 QString manual;
784 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
785 devices->endGroup();
787 QString date = (info.value("dailies/date").toString());
789 QString manualurl;
790 QString target;
791 QString section;
792 if(ui.radioPdf->isChecked()) {
793 target = "/" + manual + ".pdf";
794 section = "Manual (PDF)";
796 else {
797 target = "/" + manual + "-" + date + "-html.zip";
798 section = "Manual (HTML)";
800 manualurl = devices->value("manual_url").toString() + "/" + target;
801 qDebug() << "manualurl =" << manualurl;
803 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
804 logger->show();
805 installer = new ZipInstaller(this);
806 installer->setMountPoint(userSettings->value("defaults/mountpoint").toString());
807 if(!userSettings->value("defaults/cachedisable").toBool())
808 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
809 installer->setProxy(proxy());
810 installer->setLogSection(section);
811 installer->setUrl(manualurl);
812 installer->setUnzip(false);
813 installer->setTarget(target);
814 installer->install(logger);
818 void RbUtilQt::installPortable(void)
820 if(QMessageBox::question(this, tr("Confirm installation"),
821 tr("Do you really want to install Rockbox Utility to your player? "
822 "After installation you can run it from the players hard drive."),
823 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
824 return;
826 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
827 logger->show();
828 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
830 // check mountpoint
831 if(!QFileInfo(userSettings->value("defaults/mountpoint").toString()).isDir()) {
832 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
833 logger->abort();
834 return;
837 // remove old files first.
838 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.exe");
839 QFile::remove(userSettings->value("defaults/mountpoint").toString() + "/RockboxUtility.ini");
840 // copy currently running binary and currently used settings file
841 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("defaults/mountpoint").toString() + "/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(userSettings->fileName(), userSettings->value("defaults/mountpoint").toString() + "/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();
858 void RbUtilQt::updateInfo()
860 qDebug() << "RbUtilQt::updateInfo()";
862 QSettings log(userSettings->value("defaults/mountpoint").toString() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
863 QStringList groups = log.childGroups();
864 QList<QTreeWidgetItem *> items;
865 QTreeWidgetItem *w, *w2;
866 QString min, max;
867 int olditems = 0;
869 // remove old list entries (if any)
870 int l = ui.treeInfo->topLevelItemCount();
871 while(l--) {
872 QTreeWidgetItem *m;
873 m = ui.treeInfo->takeTopLevelItem(l);
874 // delete childs (single level deep, no recursion here)
875 int n = m->childCount();
876 while(n--)
877 delete m->child(n);
879 // get and populate new items
880 for(int a = 0; a < groups.size(); a++) {
881 log.beginGroup(groups.at(a));
882 QStringList keys = log.allKeys();
883 w = new QTreeWidgetItem;
884 w->setFlags(Qt::ItemIsEnabled);
885 w->setText(0, groups.at(a));
886 items.append(w);
887 // get minimum and maximum version information so we can hilight old files
888 min = max = log.value(keys.at(0)).toString();
889 for(int b = 0; b < keys.size(); b++) {
890 if(log.value(keys.at(b)).toString() > max)
891 max = log.value(keys.at(b)).toString();
892 if(log.value(keys.at(b)).toString() < min)
893 min = log.value(keys.at(b)).toString();
896 for(int b = 0; b < keys.size(); b++) {
897 QString file;
898 file = userSettings->value("defaults/mountpoint").toString() + "/" + keys.at(b);
899 if(QFileInfo(file).isDir())
900 continue;
901 w2 = new QTreeWidgetItem(w, QStringList() << "/"
902 + keys.at(b) << log.value(keys.at(b)).toString());
903 if(log.value(keys.at(b)).toString() != max) {
904 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
905 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
906 olditems++;
908 items.append(w2);
910 log.endGroup();
911 if(min != max)
912 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
913 else
914 w->setData(1, Qt::DisplayRole, max);
916 ui.treeInfo->insertTopLevelItems(0, items);
917 ui.treeInfo->resizeColumnToContents(0);
921 QUrl RbUtilQt::proxy()
923 if(userSettings->value("defaults/proxytype") == "manual")
924 return QUrl(userSettings->value("defaults/proxy").toString());
925 #ifdef __linux
926 else if(userSettings->value("defaults/proxytype") == "system")
927 return QUrl(getenv("http_proxy"));
928 #endif
929 return QUrl("");