Fix typo.
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob2951a892df39c8b83a0e716abc829ac3a68dab04
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 #if defined(Q_OS_LINUX)
36 #include <stdio.h>
37 #endif
38 #if defined(Q_OS_WIN32)
39 #if defined(UNICODE)
40 #define _UNICODE
41 #endif
42 #include <stdio.h>
43 #include <tchar.h>
44 #include <windows.h>
45 #endif
47 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
49 absolutePath = qApp->applicationDirPath();
50 // use built-in rbutil.ini if no external file in binary folder
51 QString iniFile = absolutePath + "/rbutil.ini";
52 if(QFileInfo(iniFile).isFile()) {
53 qDebug() << "using external rbutil.ini";
54 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
56 else {
57 qDebug() << "using built-in rbutil.ini";
58 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
61 ui.setupUi(this);
63 // portable installation:
64 // check for a configuration file in the program folder.
65 QFileInfo config;
66 config.setFile(absolutePath + "/RockboxUtility.ini");
67 if(config.isFile()) {
68 userSettings = new QSettings(absolutePath + "/RockboxUtility.ini",
69 QSettings::IniFormat, 0);
70 qDebug() << "config: portable";
72 else {
73 userSettings = new QSettings(QSettings::IniFormat,
74 QSettings::UserScope, "rockbox.org", "RockboxUtility");
75 qDebug() << "config: system";
78 // manual tab
79 updateManual();
80 updateDevice();
81 ui.radioPdf->setChecked(true);
83 // info tab
84 ui.treeInfo->setAlternatingRowColors(true);
85 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
86 ui.treeInfo->expandAll();
87 ui.treeInfo->setColumnCount(2);
89 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
90 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
91 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
92 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
93 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
94 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
95 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
96 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
97 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
98 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
99 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
100 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
101 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
102 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
103 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
104 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
105 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
106 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
108 #if !defined(STATIC)
109 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
110 #else
111 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
112 #endif
114 initIpodpatcher();
115 initSansapatcher();
116 downloadInfo();
121 void RbUtilQt::updateTabs(int count)
123 switch(count) {
124 case 6:
125 updateInfo();
126 break;
127 default:
128 break;
133 void RbUtilQt::downloadInfo()
135 // try to get the current build information
136 daily = new HttpGet(this);
137 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
138 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
139 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
140 daily->setProxy(proxy());
141 if(userSettings->value("offline").toBool())
142 daily->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
143 qDebug() << "downloading build info";
144 daily->setFile(&buildInfo);
145 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
149 void RbUtilQt::downloadDone(bool error)
151 if(error) {
152 qDebug() << "network error:" << daily->error();
153 return;
155 qDebug() << "network status:" << daily->error();
157 buildInfo.open();
158 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
159 buildInfo.close();
160 versmap.insert("arch_rev", info.value("dailies/rev").toString());
161 versmap.insert("arch_date", info.value("dailies/date").toString());
163 bleeding = new HttpGet(this);
164 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
165 connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
166 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
167 bleeding->setProxy(proxy());
168 if(userSettings->value("offline").toBool())
169 bleeding->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
170 bleeding->setFile(&bleedingInfo);
171 bleeding->getFile(QUrl(devices->value("bleeding_info").toString()));
173 if(chkConfig(false)) {
174 QApplication::processEvents();
175 QMessageBox::critical(this, tr("Configuration error"),
176 tr("Your configuration is invalid. This is most likely due "
177 "to a new installation of Rockbox Utility or a changed device "
178 "path. The configuation dialog will now open to allow you "
179 "correcting the problem."));
180 configDialog();
185 void RbUtilQt::downloadBleedingDone(bool error)
187 if(error) qDebug() << "network error:" << bleeding->error();
189 bleedingInfo.open();
190 QSettings info(bleedingInfo.fileName(), QSettings::IniFormat, this);
191 bleedingInfo.close();
192 versmap.insert("bleed_rev", info.value("bleeding/rev").toString());
193 versmap.insert("bleed_date", info.value("bleeding/timestamp").toString());
194 qDebug() << "versmap =" << versmap;
198 void RbUtilQt::downloadDone(int id, bool error)
200 QString errorString;
201 errorString = tr("Network error: %1. Please check your network and proxy settings.")
202 .arg(daily->errorString());
203 if(error) {
204 QMessageBox::about(this, "Network Error", errorString);
206 qDebug() << "downloadDone:" << id << error;
210 void RbUtilQt::about()
212 QDialog *window = new QDialog(this);
213 Ui::aboutBox about;
214 about.setupUi(window);
215 window->setModal(true);
217 QFile licence(":/docs/gpl-2.0.html");
218 licence.open(QIODevice::ReadOnly);
219 QTextStream c(&licence);
220 QString cline = c.readAll();
221 about.browserLicense->insertHtml(cline);
222 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
223 QFile credits(":/docs/CREDITS");
224 credits.open(QIODevice::ReadOnly);
225 QTextStream r(&credits);
226 QString rline = r.readAll();
227 about.browserCredits->insertPlainText(rline);
228 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
229 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION);
230 about.labelTitle->setText(title);
231 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
233 window->show();
238 void RbUtilQt::help()
240 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtilityQt");
241 QDesktopServices::openUrl(helpurl);
245 void RbUtilQt::configDialog()
247 Config *cw = new Config(this);
248 cw->setUserSettings(userSettings);
249 cw->setDevices(devices);
250 cw->show();
251 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
252 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
256 void RbUtilQt::updateSettings()
258 qDebug() << "updateSettings()";
259 updateDevice();
260 updateManual();
264 void RbUtilQt::updateDevice()
266 platform = userSettings->value("platform").toString();
267 // buttons
268 devices->beginGroup(platform);
269 if(devices->value("needsbootloader", "") == "no") {
270 ui.buttonBootloader->setEnabled(false);
271 ui.buttonRemoveBootloader->setEnabled(false);
272 ui.labelBootloader->setEnabled(false);
273 ui.labelRemoveBootloader->setEnabled(false);
275 else {
276 ui.buttonBootloader->setEnabled(true);
277 ui.labelBootloader->setEnabled(true);
278 if(devices->value("bootloadermethod") == "fwpatcher") {
279 ui.labelRemoveBootloader->setEnabled(false);
280 ui.buttonRemoveBootloader->setEnabled(false);
282 else {
283 ui.labelRemoveBootloader->setEnabled(true);
284 ui.buttonRemoveBootloader->setEnabled(true);
287 devices->endGroup();
288 // displayed device info
289 platform = userSettings->value("platform").toString();
290 QString mountpoint = userSettings->value("mountpoint").toString();
291 devices->beginGroup(platform);
292 QString brand = devices->value("brand").toString();
293 QString name = devices->value("name").toString();
294 devices->endGroup();
295 if(name.isEmpty()) name = "&lt;none&gt;";
296 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
297 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
298 .arg(brand, name, mountpoint));
302 void RbUtilQt::updateManual()
304 if(userSettings->value("platform").toString() != "")
306 devices->beginGroup(userSettings->value("platform").toString());
307 QString manual;
308 manual = devices->value("manualname", "").toString();
310 if(manual == "")
311 manual = "rockbox-" + devices->value("platform").toString();
312 devices->endGroup();
313 QString pdfmanual;
314 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
315 QString htmlmanual;
316 htmlmanual = devices->value("manual_url").toString() + "/" + 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;
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 = userSettings->value("mountpoint").toString();
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 devices->beginGroup(userSettings->value("platform").toString());
407 if(devices->value("needsbootloader", "") == "yes") {
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();
421 devices->endGroup();
423 // Rockbox
424 m_error = false;
425 m_installed = false;
426 if(!installAuto())
427 return true;
428 else
430 // wait for installation finished
431 while(!m_installed)
432 QApplication::processEvents();
435 return false;
438 void RbUtilQt::installdone(bool error)
440 qDebug() << "install done";
441 m_installed = true;
442 m_error = error;
445 void RbUtilQt::installBtn()
447 if(chkConfig(true)) return;
448 install();
451 bool RbUtilQt::installAuto()
453 QString file = QString("%1%2/rockbox.zip")
454 .arg(devices->value("bleeding_url").toString(),
455 userSettings->value("platform").toString());
457 buildInfo.open();
458 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
459 buildInfo.close();
461 devices->beginGroup(platform);
462 QString released = devices->value("released").toString();
463 devices->endGroup();
464 if(released == "yes") {
465 // only set the keys if needed -- querying will yield an empty string
466 // if not set.
467 versmap.insert("rel_rev", devices->value("last_release").toString());
468 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
471 QString myversion = "r" + versmap.value("bleed_rev");
473 ZipInstaller* installer = new ZipInstaller(this);
474 installer->setUrl(file);
475 installer->setProxy(proxy());
476 installer->setLogSection("Rockbox (Base)");
477 installer->setLogVersion(myversion);
478 if(!userSettings->value("cachedisable").toBool())
479 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
480 installer->setMountPoint(userSettings->value("mountpoint").toString());
481 installer->install(logger);
483 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
485 return true;
488 void RbUtilQt::install()
490 Install *installWindow = new Install(this);
491 installWindow->setUserSettings(userSettings);
492 installWindow->setDeviceSettings(devices);
493 installWindow->setProxy(proxy());
495 buildInfo.open();
496 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
497 buildInfo.close();
499 devices->beginGroup(platform);
500 QString released = devices->value("released").toString();
501 devices->endGroup();
502 if(released == "yes") {
503 // only set the keys if needed -- querying will yield an empty string
504 // if not set.
505 versmap.insert("rel_rev", devices->value("last_release").toString());
506 versmap.insert("rel_date", ""); // FIXME: provide the release timestamp
508 installWindow->setVersionStrings(versmap);
510 installWindow->show();
513 bool RbUtilQt::installBootloaderAuto()
515 installBootloader();
516 connect(blinstaller,SIGNAL(done(bool)),this,SLOT(installdone(bool)));
517 return !m_error;
520 void RbUtilQt::installBootloaderBtn()
522 if(chkConfig(true)) return;
523 if(QMessageBox::question(this, tr("Confirm Installation"),
524 tr("Do you really want to install the Bootloader?"),
525 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
527 // create logger
528 logger = new ProgressLoggerGui(this);
529 logger->show();
531 installBootloader();
534 void RbUtilQt::installBootloader()
536 QString platform = userSettings->value("platform").toString();
538 // create installer
539 blinstaller = new BootloaderInstaller(this);
541 blinstaller->setMountPoint(userSettings->value("mountpoint").toString());
543 blinstaller->setProxy(proxy());
544 blinstaller->setDevice(platform);
545 blinstaller->setBootloaderMethod(devices->value(platform + "/bootloadermethod").toString());
546 blinstaller->setBootloaderName(devices->value(platform + "/bootloadername").toString());
547 blinstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
548 blinstaller->setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
549 if(!blinstaller->downloadInfo())
551 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
552 logger->abort();
553 m_error = true;
554 return;
557 if(blinstaller->uptodate())
559 int ret = QMessageBox::question(this, tr("Bootloader Installation"),
560 tr("It seem your Bootloader is already up to date.\n"
561 "Do really want to install it?"),
562 QMessageBox::Ok | QMessageBox::Ignore |QMessageBox::Cancel,
563 QMessageBox::Cancel);
564 if(ret == QMessageBox::Cancel)
566 logger->addItem(tr("Bootloader installation canceled!"),LOGERROR);
567 logger->abort();
568 m_error = true;
569 return;
571 else if(ret == QMessageBox::Ignore)
573 logger->addItem(tr("Bootloader installation skipped!"),LOGERROR);
574 logger->abort();
575 m_installed = true;
576 return;
580 // if fwpatcher , ask for extra file
581 QString offirmware;
582 if(devices->value(platform + "/bootloadermethod").toString() == "fwpatcher")
584 BrowseOF ofbrowser(this);
585 ofbrowser.setFile(userSettings->value("ofpath").toString());
586 if(ofbrowser.exec() == QDialog::Accepted)
588 offirmware = ofbrowser.getFile();
589 qDebug() << offirmware;
590 if(!QFileInfo(offirmware).exists())
592 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
593 logger->abort();
594 m_error = true;
595 return;
597 else
599 userSettings->setValue("ofpath",offirmware);
600 userSettings->sync();
603 else
605 logger->addItem(tr("Original Firmware selection Canceled!"),LOGERROR);
606 logger->abort();
607 m_error = true;
608 return;
611 blinstaller->setOrigFirmwarePath(offirmware);
613 blinstaller->install(logger);
616 void RbUtilQt::installFontsBtn()
618 if(chkConfig(true)) return;
619 if(QMessageBox::question(this, tr("Confirm Installation"),
620 tr("Do you really want to install the fonts package?"),
621 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
622 // create logger
623 logger = new ProgressLoggerGui(this);
624 logger->show();
625 installFonts();
628 bool RbUtilQt::installFontsAuto()
630 installFonts();
631 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
632 return !m_error;
635 void RbUtilQt::installFonts()
637 // create zip installer
638 installer = new ZipInstaller(this);
640 installer->setUrl(devices->value("font_url").toString());
641 installer->setProxy(proxy());
642 installer->setLogSection("Fonts");
643 installer->setLogVersion(versmap.value("arch_date"));
644 installer->setMountPoint(userSettings->value("mountpoint").toString());
645 if(!userSettings->value("cachedisable").toBool())
646 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
647 installer->install(logger);
651 void RbUtilQt::installVoice()
653 if(chkConfig(true)) return;
654 if(QMessageBox::question(this, tr("Confirm Installation"),
655 tr("Do you really want to install the voice file?"),
656 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
657 // create logger
658 logger = new ProgressLoggerGui(this);
659 logger->show();
661 // create zip installer
662 installer = new ZipInstaller(this);
663 installer->setUnzip(false);
665 QString voiceurl = devices->value("voice_url").toString() + "/" +
666 userSettings->value("platform").toString() + "-" +
667 versmap.value("arch_date") + "-english.voice";
668 qDebug() << voiceurl;
670 installer->setProxy(proxy());
671 installer->setUrl(voiceurl);
672 installer->setLogSection("Voice");
673 installer->setLogVersion(versmap.value("arch_date"));
674 installer->setMountPoint(userSettings->value("mountpoint").toString());
675 installer->setTarget("/.rockbox/langs/english.voice");
676 if(!userSettings->value("cachedisable").toBool())
677 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
678 installer->install(logger);
680 //connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
683 void RbUtilQt::installDoomBtn()
685 if(chkConfig(true)) return;
686 if(!hasDoom()){
687 QMessageBox::critical(this, tr("Error"), tr("Your device doesn't have a doom plugin. Aborting."));
688 return;
691 if(QMessageBox::question(this, tr("Confirm Installation"),
692 tr("Do you really want to install the game addon files?"),
693 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
694 // create logger
695 logger = new ProgressLoggerGui(this);
696 logger->show();
698 installDoom();
700 bool RbUtilQt::installDoomAuto()
702 installDoom();
703 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
704 return !m_error;
707 bool RbUtilQt::hasDoom()
709 QFile doomrock(userSettings->value("mountpoint").toString()+"/.rockbox/rocks/games/doom.rock");
710 return doomrock.exists();
713 void RbUtilQt::installDoom()
715 // create zip installer
716 installer = new ZipInstaller(this);
718 installer->setUrl(devices->value("doom_url").toString());
719 installer->setProxy(proxy());
720 installer->setLogSection("Game Addons");
721 installer->setLogVersion(versmap.value("arch_date"));
722 installer->setMountPoint(userSettings->value("mountpoint").toString());
723 if(!userSettings->value("cachedisable").toBool())
724 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
725 installer->install(logger);
730 void RbUtilQt::installThemes()
732 if(chkConfig(true)) return;
733 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
734 tw->setDeviceSettings(devices);
735 tw->setUserSettings(userSettings);
736 tw->setProxy(proxy());
737 tw->setModal(true);
738 tw->show();
742 void RbUtilQt::createTalkFiles(void)
744 if(chkConfig(true)) return;
745 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
746 installWindow->setUserSettings(userSettings);
747 installWindow->setDeviceSettings(devices);
748 installWindow->show();
752 void RbUtilQt::uninstall(void)
754 if(chkConfig(true)) return;
755 UninstallWindow *uninstallWindow = new UninstallWindow(this);
756 uninstallWindow->setUserSettings(userSettings);
757 uninstallWindow->setDeviceSettings(devices);
758 uninstallWindow->show();
761 void RbUtilQt::uninstallBootloader(void)
763 if(chkConfig(true)) return;
764 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
765 tr("Do you really want to uninstall the Bootloader?"),
766 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
767 // create logger
768 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
769 logger->show();
771 QString plattform = userSettings->value("platform").toString();
772 BootloaderInstaller blinstaller(this);
773 blinstaller.setProxy(proxy());
774 blinstaller.setMountPoint(userSettings->value("mountpoint").toString());
775 blinstaller.setDevice(userSettings->value("platform").toString());
776 blinstaller.setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
777 blinstaller.setBootloaderName(devices->value(plattform + "/bootloadername").toString());
778 blinstaller.setBootloaderBaseUrl(devices->value("bootloader_url").toString());
779 blinstaller.setBootloaderInfoUrl(devices->value("bootloader_info_url").toString());
780 if(!blinstaller.downloadInfo())
782 logger->addItem(tr("Could not get the bootloader info file!"),LOGERROR);
783 logger->abort();
784 return;
787 blinstaller.uninstall(logger);
792 void RbUtilQt::downloadManual(void)
794 if(chkConfig(true)) return;
795 if(QMessageBox::question(this, tr("Confirm download"),
796 tr("Do you really want to download the manual? The manual will be saved "
797 "to the root folder of your player."),
798 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
799 return;
801 buildInfo.open();
802 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
803 buildInfo.close();
805 devices->beginGroup(userSettings->value("platform").toString());
806 QString manual;
807 manual = devices->value("manualname", "rockbox-" + devices->value("platform").toString()).toString();
808 devices->endGroup();
810 QString date = (info.value("dailies/date").toString());
812 QString manualurl;
813 QString target;
814 QString section;
815 if(ui.radioPdf->isChecked()) {
816 target = "/" + manual + ".pdf";
817 section = "Manual (PDF)";
819 else {
820 target = "/" + manual + "-" + date + "-html.zip";
821 section = "Manual (HTML)";
823 manualurl = devices->value("manual_url").toString() + "/" + target;
824 qDebug() << "manualurl =" << manualurl;
826 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
827 logger->show();
828 installer = new ZipInstaller(this);
829 installer->setMountPoint(userSettings->value("mountpoint").toString());
830 if(!userSettings->value("cachedisable").toBool())
831 installer->setCache(userSettings->value("cachepath", QDir::tempPath()).toString());
832 installer->setProxy(proxy());
833 installer->setLogSection(section);
834 installer->setUrl(manualurl);
835 installer->setUnzip(false);
836 installer->setTarget(target);
837 installer->install(logger);
841 void RbUtilQt::installPortable(void)
843 if(QMessageBox::question(this, tr("Confirm installation"),
844 tr("Do you really want to install Rockbox Utility to your player? "
845 "After installation you can run it from the players hard drive."),
846 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
847 return;
849 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
850 logger->show();
851 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
853 // check mountpoint
854 if(!QFileInfo(userSettings->value("mountpoint").toString()).isDir()) {
855 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
856 logger->abort();
857 return;
860 // remove old files first.
861 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.exe");
862 QFile::remove(userSettings->value("mountpoint").toString() + "/RockboxUtility.ini");
863 // copy currently running binary and currently used settings file
864 if(!QFile::copy(qApp->applicationFilePath(), userSettings->value("mountpoint").toString() + "/RockboxUtility.exe")) {
865 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
866 logger->abort();
867 return;
869 logger->addItem(tr("Installing user configuration"), LOGINFO);
870 if(!QFile::copy(userSettings->fileName(), userSettings->value("mountpoint").toString() + "/RockboxUtility.ini")) {
871 logger->addItem(tr("Error installing user configuration"), LOGERROR);
872 logger->abort();
873 return;
875 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
876 logger->abort();
881 void RbUtilQt::updateInfo()
883 qDebug() << "RbUtilQt::updateInfo()";
885 QSettings log(userSettings->value("mountpoint").toString() + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
886 QStringList groups = log.childGroups();
887 QList<QTreeWidgetItem *> items;
888 QTreeWidgetItem *w, *w2;
889 QString min, max;
890 int olditems = 0;
892 // remove old list entries (if any)
893 int l = ui.treeInfo->topLevelItemCount();
894 while(l--) {
895 QTreeWidgetItem *m;
896 m = ui.treeInfo->takeTopLevelItem(l);
897 // delete childs (single level deep, no recursion here)
898 int n = m->childCount();
899 while(n--)
900 delete m->child(n);
902 // get and populate new items
903 for(int a = 0; a < groups.size(); a++) {
904 log.beginGroup(groups.at(a));
905 QStringList keys = log.allKeys();
906 w = new QTreeWidgetItem;
907 w->setFlags(Qt::ItemIsEnabled);
908 w->setText(0, groups.at(a));
909 items.append(w);
910 // get minimum and maximum version information so we can hilight old files
911 min = max = log.value(keys.at(0)).toString();
912 for(int b = 0; b < keys.size(); b++) {
913 if(log.value(keys.at(b)).toString() > max)
914 max = log.value(keys.at(b)).toString();
915 if(log.value(keys.at(b)).toString() < min)
916 min = log.value(keys.at(b)).toString();
919 for(int b = 0; b < keys.size(); b++) {
920 QString file;
921 file = userSettings->value("mountpoint").toString() + "/" + keys.at(b);
922 if(QFileInfo(file).isDir())
923 continue;
924 w2 = new QTreeWidgetItem(w, QStringList() << "/"
925 + keys.at(b) << log.value(keys.at(b)).toString());
926 if(log.value(keys.at(b)).toString() != max) {
927 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
928 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
929 olditems++;
931 items.append(w2);
933 log.endGroup();
934 if(min != max)
935 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
936 else
937 w->setData(1, Qt::DisplayRole, max);
939 ui.treeInfo->insertTopLevelItems(0, items);
940 ui.treeInfo->resizeColumnToContents(0);
944 QUrl RbUtilQt::proxy()
946 if(userSettings->value("proxytype", "system").toString() == "manual")
947 return QUrl(userSettings->value("proxy").toString());
948 #if defined(Q_OS_LINUX)
949 else if(userSettings->value("proxytype", "system").toString() == "system")
950 return QUrl(getenv("http_proxy"));
951 #endif
952 #if defined(Q_OS_WIN32)
953 HKEY hk;
954 wchar_t proxyval[80];
955 DWORD buflen = 80;
956 long ret;
958 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
959 0, KEY_QUERY_VALUE, &hk);
960 if(ret != ERROR_SUCCESS) return QUrl("");
962 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
963 if(ret != ERROR_SUCCESS) return QUrl("");
965 RegCloseKey(hk);
966 qDebug() << QString::fromWCharArray(proxyval);
967 return QUrl("http://" + QString::fromWCharArray(proxyval));
969 #endif
970 return QUrl("");
974 bool RbUtilQt::chkConfig(bool warn)
976 bool error = false;
977 if(userSettings->value("platform").toString().isEmpty()
978 || userSettings->value("mountpoint").toString().isEmpty()
979 || !QFileInfo(userSettings->value("mountpoint").toString()).isWritable()) {
980 error = true;
982 if(warn) QMessageBox::critical(this, tr("Configuration error"),
983 tr("Your configuration is invalid. Please go to the configuration "
984 "dialog and make sure the selected values are correct."));
986 return error;