Prefix compareversion test files.
[maemo-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blob4836cf567d7e1428ff189e06a40bd3425efe84e6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtGui>
21 #include "version.h"
22 #include "rbutilqt.h"
23 #include "ui_rbutilqtfrm.h"
24 #include "ui_aboutbox.h"
25 #include "configure.h"
26 #include "installwindow.h"
27 #include "installtalkwindow.h"
28 #include "createvoicewindow.h"
29 #include "httpget.h"
30 #include "themesinstallwindow.h"
31 #include "uninstallwindow.h"
32 #include "utils.h"
33 #include "rockboxinfo.h"
34 #include "sysinfo.h"
35 #include "system.h"
36 #include "systrace.h"
37 #include "rbsettings.h"
38 #include "serverinfo.h"
39 #include "systeminfo.h"
40 #include "ziputil.h"
41 #include "manualwidget.h"
42 #include "infowidget.h"
44 #include "progressloggerinterface.h"
46 #include "bootloaderinstallbase.h"
47 #include "bootloaderinstallmpio.h"
49 #if defined(Q_OS_LINUX)
50 #include <stdio.h>
51 #endif
52 #if defined(Q_OS_WIN32)
53 #if defined(UNICODE)
54 #define _UNICODE
55 #endif
56 #include <stdio.h>
57 #include <tchar.h>
58 #include <windows.h>
59 #endif
61 QList<QTranslator*> RbUtilQt::translators;
63 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
65 // startup log
66 qDebug() << "======================================";
67 qDebug() << "[System] Rockbox Utility " VERSION;
68 qDebug() << "[System] Qt version:" << qVersion();
69 qDebug() << "======================================";
71 absolutePath = qApp->applicationDirPath();
73 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
74 HttpGet::setGlobalProxy(proxy());
75 // init startup & autodetection
76 ui.setupUi(this);
77 #if defined(Q_OS_LINUX)
78 QIcon windowIcon(":/icons/rockbox-clef.svg");
79 this->setWindowIcon(windowIcon);
80 #endif
81 #if defined(Q_OS_WIN32)
82 QIcon windowIcon = QIcon();
83 windowIcon.addFile(":/icons/rockbox-16.png");
84 windowIcon.addFile(":/icons/rockbox-32.png");
85 windowIcon.addFile(":/icons/rockbox-48.png");
86 windowIcon.addFile(":/icons/rockbox-64.png");
87 windowIcon.addFile(":/icons/rockbox-128.png");
88 windowIcon.addFile(":/icons/rockbox-256.png");
89 this->setWindowIcon(windowIcon);
90 #endif
91 #if defined(Q_OS_MACX)
92 // don't translate menu entries that are handled specially on OS X
93 // (Configure, Quit). Qt handles them for us if they use english string.
94 ui.action_Configure->setText("Configure");
95 ui.actionE_xit->setText("Quit");
96 #endif
97 #if defined(Q_OS_WIN32)
98 long ret;
99 HKEY hk;
100 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Wine"),
101 0, KEY_QUERY_VALUE, &hk);
102 if(ret == ERROR_SUCCESS) {
103 QMessageBox::warning(this, tr("Wine detected!"),
104 tr("It seems you are trying to run this program under Wine. "
105 "Please don't do this, running under Wine will fail. "
106 "Use the native Linux binary instead."),
107 QMessageBox::Ok, QMessageBox::Ok);
108 qDebug() << "[RbUtil] WINE DETECTED!";
109 RegCloseKey(hk);
111 #endif
112 updateDevice();
113 downloadInfo();
115 m_gotInfo = false;
116 m_auto = false;
118 // insert ManualWidget() widget in manual tab
119 QGridLayout *mantablayout = new QGridLayout(this);
120 ui.manual->setLayout(mantablayout);
121 manual = new ManualWidget(this);
122 mantablayout->addWidget(manual);
124 // info tab
125 QGridLayout *infotablayout = new QGridLayout(this);
126 ui.info->setLayout(infotablayout);
127 info = new InfoWidget(this);
128 infotablayout->addWidget(info);
130 // disable quick install until version info is available
131 ui.buttonSmall->setEnabled(false);
132 ui.buttonComplete->setEnabled(false);
133 ui.actionSmall_Installation->setEnabled(false);
134 ui.actionComplete_Installation->setEnabled(false);
136 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
137 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
138 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
139 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
140 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
141 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
142 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
143 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
144 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
145 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
146 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
147 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
148 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
149 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
150 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
151 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
152 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
153 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
154 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
156 // actions accessible from the menu
157 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
158 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
159 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
160 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
161 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
162 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
163 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
164 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
165 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
166 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
167 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
168 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
169 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
170 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
172 #if !defined(STATIC)
173 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
174 #else
175 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
176 #endif
177 Utils::findRunningProcess(QStringList("iTunes"));
182 void RbUtilQt::shutdown(void)
184 // restore default message handler to prevent trace accesses during
185 // object destruction -- the trace object could already be destroyed.
186 // Fixes segfaults on exit.
187 qInstallMsgHandler(0);
188 SysTrace::save();
189 this->close();
193 void RbUtilQt::trace(void)
195 SysTrace wnd(this);
196 wnd.exec();
199 void RbUtilQt::sysinfo(void)
201 Sysinfo info(this);
202 info.exec();
205 void RbUtilQt::updateTabs(int count)
207 switch(count) {
208 case 6:
209 info->updateInfo();
210 break;
211 default:
212 break;
217 void RbUtilQt::downloadInfo()
219 // try to get the current build information
220 daily = new HttpGet(this);
221 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
222 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
223 if(RbSettings::value(RbSettings::CacheOffline).toBool())
224 daily->setCache(true);
225 else
226 daily->setCache(false);
227 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
228 qDebug() << "[RbUtil] downloading build info";
229 daily->setFile(&buildInfo);
230 daily->getFile(QUrl(SystemInfo::value(SystemInfo::ServerConfUrl).toString()));
234 void RbUtilQt::downloadDone(bool error)
236 if(error) {
237 qDebug() << "[RbUtil] network error:" << daily->error();
238 ui.statusbar->showMessage(tr("Can't get version information!"));
239 QMessageBox::critical(this, tr("Network error"),
240 tr("Can't get version information.\n"
241 "Network error: %1. Please check your network and proxy settings.")
242 .arg(daily->errorString()));
243 return;
245 qDebug() << "[RbUtil] network status:" << daily->error();
247 // read info into ServerInfo object
248 buildInfo.open();
249 ServerInfo::readBuildInfo(buildInfo.fileName());
250 buildInfo.close();
252 // start bleeding info download
253 bleeding = new HttpGet(this);
254 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
255 connect(qApp, SIGNAL(lastWindowClosed()), bleeding, SLOT(abort()));
256 if(RbSettings::value(RbSettings::CacheOffline).toBool())
257 bleeding->setCache(true);
258 bleeding->setFile(&bleedingInfo);
259 bleeding->getFile(QUrl(SystemInfo::value(SystemInfo::BleedingInfo).toString()));
260 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
265 void RbUtilQt::downloadBleedingDone(bool error)
267 if(error) {
268 qDebug() << "[RbUtil] network error:" << bleeding->error();
269 ui.statusbar->showMessage(tr("Can't get version information!"));
270 QMessageBox::critical(this, tr("Network error"),
271 tr("Can't get version information.\n"
272 "Network error: %1. Please check your network and proxy settings.")
273 .arg(bleeding->errorString()));
274 return;
276 else {
277 bleedingInfo.open();
278 ServerInfo::readBleedingInfo(bleedingInfo.fileName());
279 bleedingInfo.close();
281 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
282 updateSettings();
283 m_gotInfo = true;
285 //start check for updates
286 checkUpdate();
291 void RbUtilQt::about()
293 QDialog *window = new QDialog(this);
294 Ui::aboutBox about;
295 about.setupUi(window);
296 window->setLayoutDirection(Qt::LeftToRight);
297 window->setModal(true);
299 QFile licence(":/docs/gpl-2.0.html");
300 licence.open(QIODevice::ReadOnly);
301 QTextStream c(&licence);
302 about.browserLicense->insertHtml(c.readAll());
303 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
305 QFile speexlicense(":/docs/COPYING.SPEEX");
306 speexlicense.open(QIODevice::ReadOnly);
307 QTextStream s(&speexlicense);
308 about.browserSpeexLicense->insertHtml("<pre>" + s.readAll() + "</pre>");
309 about.browserSpeexLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
311 QFile credits(":/docs/CREDITS");
312 credits.open(QIODevice::ReadOnly);
313 QTextStream r(&credits);
314 r.setCodec(QTextCodec::codecForName("UTF-8"));
315 while(!r.atEnd()) {
316 QString line = r.readLine();
317 // filter out header.
318 line.remove(QRegExp("^ +.*"));
319 line.remove(QRegExp("^People.*"));
320 about.browserCredits->append(line);
322 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
323 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
324 about.labelTitle->setText(title);
326 window->show();
331 void RbUtilQt::help()
333 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
334 QDesktopServices::openUrl(helpurl);
338 void RbUtilQt::configDialog()
340 Config *cw = new Config(this);
341 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
342 cw->show();
346 void RbUtilQt::updateSettings()
348 qDebug() << "[RbUtil] updating current settings";
349 updateDevice();
350 manual->updateManual();
351 HttpGet::setGlobalProxy(proxy());
352 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
353 HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
355 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
356 QApplication::processEvents();
357 QMessageBox::information(this, tr("New installation"),
358 tr("This is a new installation of Rockbox Utility, or a new version. "
359 "The configuration dialog will now open to allow you to setup the program, "
360 " or review your settings."));
361 configDialog();
363 else if(chkConfig(0)) {
364 QApplication::processEvents();
365 QMessageBox::critical(this, tr("Configuration error"),
366 tr("Your configuration is invalid. This is most likely due "
367 "to a changed device path. The configuration dialog will "
368 "now open to allow you to correct the problem."));
369 configDialog();
374 void RbUtilQt::updateDevice()
376 /* TODO: We should check the flags of the bootloaderinstall classes, and not
377 * just check if its != none or != "fwpatcher" */
379 /* Enable bootloader installation, if possible */
380 bool bootloaderInstallable =
381 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
382 ui.buttonBootloader->setEnabled(bootloaderInstallable);
383 ui.labelBootloader->setEnabled(bootloaderInstallable);
384 ui.actionInstall_Bootloader->setEnabled(bootloaderInstallable);
386 /* Enable bootloader uninstallation, if possible */
387 bool bootloaderUninstallable = bootloaderInstallable &&
388 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
389 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
390 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
391 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
393 /* Disable the whole tab widget if configuration is invalid */
394 bool configurationValid = !chkConfig(0);
395 ui.tabWidget->setEnabled(configurationValid);
396 ui.menuA_ctions->setEnabled(configurationValid);
398 // displayed device info
399 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
400 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
401 QString name = SystemInfo::value(SystemInfo::CurName).toString() +
402 " (" + ServerInfo::value(ServerInfo::CurStatus).toString() + ")";
403 QString mountdisplay = QDir::toNativeSeparators(mountpoint);
404 QString label = Utils::filesystemName(mountpoint);
405 if(!label.isEmpty())
406 mountdisplay += " (" + label + ")";
408 if(name.isEmpty()) name = "&lt;none&gt;";
409 if(mountpoint.isEmpty())
410 mountpoint = "&lt;invalid&gt;";
411 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
412 .arg(brand, name, mountdisplay));
414 // hide quickstart buttons if no release available
415 bool installable = !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty();
416 ui.buttonSmall->setEnabled(installable);
417 ui.buttonComplete->setEnabled(installable);
418 ui.actionSmall_Installation->setEnabled(installable);
419 ui.actionComplete_Installation->setEnabled(installable);
423 void RbUtilQt::completeInstall()
425 if(chkConfig(this)) return;
426 if(QMessageBox::question(this, tr("Confirm Installation"),
427 tr("Do you really want to perform a complete installation?\n\n"
428 "This will install Rockbox %1. To install the most recent "
429 "development build available press \"Cancel\" and "
430 "use the \"Installation\" tab.")
431 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
432 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
433 return;
434 // create logger
435 logger = new ProgressLoggerGui(this);
436 logger->show();
438 if(smallInstallInner())
439 return;
440 logger->setRunning();
441 // Fonts
442 m_error = false;
443 m_installed = false;
444 if(!installFontsAuto())
445 return;
446 else
448 // wait for installation finished
449 while(!m_installed)
450 QApplication::processEvents();
452 if(m_error) return;
453 logger->setRunning();
455 // Doom
456 if(hasDoom())
458 m_error = false;
459 m_installed = false;
460 if(!installDoomAuto())
461 return;
462 else
464 // wait for installation finished
465 while(!m_installed)
466 QApplication::processEvents();
468 if(m_error) return;
471 // theme
472 // this is a window
473 // it has its own logger window,so close our.
474 logger->close();
475 installThemes();
479 void RbUtilQt::smallInstall()
481 if(chkConfig(this)) return;
482 if(QMessageBox::question(this, tr("Confirm Installation"),
483 tr("Do you really want to perform a minimal installation? "
484 "A minimal installation will contain only the absolutely "
485 "necessary parts to run Rockbox.\n\n"
486 "This will install Rockbox %1. To install the most recent "
487 "development build available press \"Cancel\" and "
488 "use the \"Installation\" tab.")
489 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
490 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
491 return;
493 // create logger
494 logger = new ProgressLoggerGui(this);
495 logger->show();
497 smallInstallInner();
500 bool RbUtilQt::smallInstallInner()
502 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
503 // show dialog with error if mount point is wrong
504 if(!QFileInfo(mountpoint).isDir()) {
505 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
506 logger->setFinished();
507 return true;
509 // Bootloader
510 if(SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none")
512 m_error = false;
513 m_installed = false;
514 m_auto = true;
515 if(!installBootloaderAuto()) {
516 logger->setFinished();
517 return true;
519 else
521 // wait for boot loader installation finished
522 while(!m_installed)
523 QApplication::processEvents();
525 m_auto = false;
526 if(m_error) return true;
527 logger->setRunning();
530 // Rockbox
531 m_error = false;
532 m_installed = false;
533 if(!installAuto())
534 return true;
535 else
537 // wait for installation finished
538 while(!m_installed)
539 QApplication::processEvents();
542 installBootloaderPost(false);
543 return false;
546 void RbUtilQt::installdone(bool error)
548 qDebug() << "[RbUtil] install done";
549 m_installed = true;
550 m_error = error;
553 void RbUtilQt::installBtn()
555 if(chkConfig(this)) return;
556 install();
559 bool RbUtilQt::installAuto()
561 QString file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
562 file.replace("%MODEL%", SystemInfo::value(SystemInfo::CurBuildserverModel).toString());
563 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
565 // check installed Version and Target
566 QString warning = Utils::checkEnvironment(false);
567 if(!warning.isEmpty())
569 if(QMessageBox::warning(this, tr("Really continue?"), warning,
570 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
571 == QMessageBox::Abort)
573 logger->addItem(tr("Aborted!"), LOGERROR);
574 logger->setFinished();
575 return false;
579 // check version
580 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
581 if(rbinfo.version() != "")
583 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
584 tr("Rockbox installation detected. Do you want to backup first?"),
585 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
587 bool result;
588 logger->addItem(tr("Starting backup..."),LOGINFO);
589 QString backupName = RbSettings::value(RbSettings::Mountpoint).toString()
590 + "/.backup/rockbox-backup-" + rbinfo.version() + ".zip";
592 //! create dir, if it doesnt exist
593 QFileInfo backupFile(backupName);
594 if(!QDir(backupFile.path()).exists())
596 QDir a;
597 a.mkpath(backupFile.path());
600 logger->addItem(tr("Beginning Backup..."),LOGINFO);
601 QCoreApplication::processEvents();
603 //! create backup
604 ZipUtil zip(this);
605 connect(&zip, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
606 connect(&zip, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
607 zip.open(backupName, QuaZip::mdCreate);
608 QString mp = RbSettings::value(RbSettings::Mountpoint).toString();
609 QString folder = mp + "/.rockbox";
610 result = zip.appendDirToArchive(folder, mp);
611 zip.close();
612 if(result)
614 logger->addItem(tr("Backup successful"),LOGOK);
616 else
618 logger->addItem(tr("Backup failed!"),LOGERROR);
619 logger->setFinished();
620 return false;
625 //! install current build
626 ZipInstaller* installer = new ZipInstaller(this);
627 installer->setUrl(file);
628 installer->setLogSection("Rockbox (Base)");
629 installer->setLogVersion(ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
630 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
631 installer->setCache(true);
632 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
634 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
635 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
636 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
637 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
638 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
639 installer->install();
640 return true;
644 void RbUtilQt::install()
646 InstallWindow *installWindow = new InstallWindow(this);
647 installWindow->show();
650 bool RbUtilQt::installBootloaderAuto()
652 installBootloader();
653 return !m_error;
656 void RbUtilQt::installBootloaderBtn()
658 if(chkConfig(this)) return;
659 if(QMessageBox::question(this, tr("Confirm Installation"),
660 tr("Do you really want to install the Bootloader?"),
661 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
663 // create logger
664 logger = new ProgressLoggerGui(this);
665 logger->show();
666 installBootloader();
669 void RbUtilQt::installBootloader()
671 QString platform = RbSettings::value(RbSettings::Platform).toString();
672 QString backupDestination = "";
673 m_error = false;
675 // create installer
676 BootloaderInstallBase *bl = BootloaderInstallBase::createBootloaderInstaller(this,
677 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
678 if(bl == NULL) {
679 logger->addItem(tr("No install method known."), LOGERROR);
680 logger->setFinished();
681 return;
684 // the bootloader install class does NOT use any GUI stuff.
685 // All messages are passed via signals.
686 connect(bl, SIGNAL(done(bool)), logger, SLOT(setFinished()));
687 connect(bl, SIGNAL(done(bool)), this, SLOT(installBootloaderPost(bool)));
688 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
689 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
691 // set bootloader filename. Do this now as installed() needs it.
692 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
693 QStringList blfilepath;
694 for(int a = 0; a < blfile.size(); a++) {
695 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
696 + blfile.at(a));
698 bl->setBlFile(blfilepath);
699 QUrl url(SystemInfo::value(SystemInfo::BootloaderUrl).toString()
700 + SystemInfo::value(SystemInfo::CurBootloaderName).toString());
701 bl->setBlUrl(url);
702 bl->setLogfile(RbSettings::value(RbSettings::Mountpoint).toString()
703 + "/.rockbox/rbutil.log");
705 if(bl->installed() == BootloaderInstallBase::BootloaderRockbox) {
706 if(QMessageBox::question(this, tr("Bootloader detected"),
707 tr("Bootloader already installed. Do you want to reinstall the bootloader?"),
708 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
709 if(m_auto) {
710 // keep logger open for auto installs.
711 // don't consider abort as error in auto-mode.
712 logger->addItem(tr("Bootloader installation skipped"), LOGINFO);
713 installBootloaderPost(false);
715 else {
716 logger->close();
717 installBootloaderPost(true);
719 delete bl;
720 return;
723 else if(bl->installed() == BootloaderInstallBase::BootloaderOther
724 && bl->capabilities() & BootloaderInstallBase::Backup)
726 QString targetFolder = SystemInfo::value(SystemInfo::CurPlatformName).toString()
727 + " Firmware Backup";
728 // remove invalid character(s)
729 targetFolder.remove(QRegExp("[:/]"));
730 if(QMessageBox::question(this, tr("Create Bootloader backup"),
731 tr("You can create a backup of the original bootloader "
732 "file. Press \"Yes\" to select an output folder on your "
733 "computer to save the file to. The file will get placed "
734 "in a new folder \"%1\" created below the selected folder.\n"
735 "Press \"No\" to skip this step.").arg(targetFolder),
736 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
737 backupDestination = QFileDialog::getExistingDirectory(this,
738 tr("Browse backup folder"), QDir::homePath());
739 if(!backupDestination.isEmpty())
740 backupDestination += "/" + targetFolder;
742 qDebug() << "[RbUtil] backing up to" << backupDestination;
743 // backup needs to be done after the logger has been set up.
747 if(bl->capabilities() & BootloaderInstallBase::NeedsOf)
749 int ret;
750 ret = QMessageBox::information(this, tr("Prerequisites"),
751 bl->ofHint(),QMessageBox::Ok | QMessageBox::Abort);
752 if(ret != QMessageBox::Ok) {
753 // consider aborting an error to close window / abort automatic
754 // installation.
755 m_error = true;
756 logger->addItem(tr("Bootloader installation aborted"), LOGINFO);
757 logger->setFinished();
758 return;
760 // open dialog to browse to of file
761 QString offile;
762 offile = QFileDialog::getOpenFileName(this,
763 tr("Select firmware file"), QDir::homePath());
764 if(!QFileInfo(offile).isReadable()) {
765 logger->addItem(tr("Error opening firmware file"), LOGERROR);
766 logger->setFinished();
767 m_error = true;
768 return;
770 if(!bl->setOfFile(offile, blfile)) {
771 logger->addItem(tr("Error reading firmware file"), LOGERROR);
772 logger->setFinished();
773 m_error = true;
774 return;
778 // start install.
779 if(!backupDestination.isEmpty()) {
780 if(!bl->backup(backupDestination)) {
781 if(QMessageBox::warning(this, tr("Backup error"),
782 tr("Could not create backup file. Continue?"),
783 QMessageBox::No | QMessageBox::Yes)
784 == QMessageBox::No) {
785 logger->setFinished();
786 return;
790 bl->install();
793 void RbUtilQt::installBootloaderPost(bool error)
795 qDebug() << "[RbUtil] Bootloader Post-Installation, error state:" << error;
796 // if an error occured don't perform post install steps.
797 if(error) {
798 m_error = true;
799 return;
801 else
802 m_error = false;
804 m_installed = true;
805 // end here if automated install
806 if(m_auto)
807 return;
809 QString msg = BootloaderInstallBase::postinstallHints(
810 RbSettings::value(RbSettings::Platform).toString());
811 if(!msg.isEmpty()) {
812 QMessageBox::information(this, tr("Manual steps required"), msg);
813 logger->close();
818 void RbUtilQt::installFontsBtn()
820 if(chkConfig(this)) return;
821 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
822 RockboxInfo installInfo(mountpoint);
823 if(installInfo.revision().isEmpty() && installInfo.release().isEmpty()) {
824 QMessageBox::critical(this, tr("No Rockbox installation found"),
825 tr("Could not determine the installed Rockbox version. "
826 "Please install a Rockbox build before installing "
827 "fonts."));
828 return;
830 if(QMessageBox::question(this, tr("Confirm Installation"),
831 tr("Do you really want to install the fonts package?"),
832 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
833 // create logger
834 logger = new ProgressLoggerGui(this);
835 logger->show();
836 installFonts();
839 bool RbUtilQt::installFontsAuto()
841 installFonts();
843 return !m_error;
846 void RbUtilQt::installFonts()
848 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
849 RockboxInfo installInfo(mountpoint);
850 QString fontsurl;
851 QString logversion;
852 QString relversion = installInfo.release();
853 if(relversion.isEmpty()) {
854 // release is empty for non-release versions (i.e. daily / current)
855 fontsurl = SystemInfo::value(SystemInfo::DailyFontUrl).toString();
856 logversion = installInfo.revision();
858 else {
859 fontsurl = SystemInfo::value(SystemInfo::ReleaseFontUrl).toString();
860 logversion = installInfo.release();
862 fontsurl.replace("%RELEASEVER%", relversion);
864 // create zip installer
865 installer = new ZipInstaller(this);
866 installer->setUrl(fontsurl);
867 installer->setLogSection("Fonts");
868 installer->setLogVersion(logversion);
869 installer->setMountPoint(mountpoint);
870 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
871 installer->setCache(true);
873 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
874 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
875 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
876 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
877 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
878 installer->install();
882 void RbUtilQt::installVoice()
884 if(chkConfig(this)) return;
886 if(m_gotInfo == false)
888 QMessageBox::warning(this, tr("Warning"),
889 tr("The Application is still downloading Information about new Builds."
890 " Please try again shortly."));
891 return;
894 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
895 RockboxInfo installInfo(mountpoint);
897 QString voiceurl;
898 QString logversion;
899 QString relversion = installInfo.release();
900 // if no version is found abort.
901 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
902 QMessageBox::critical(this, tr("No Rockbox installation found"),
903 tr("Could not determine the installed Rockbox version. "
904 "Please install a Rockbox build before installing "
905 "voice files."));
906 return;
908 if(relversion.isEmpty()) {
909 // release is empty for non-release versions (i.e. daily / current)
910 voiceurl = SystemInfo::value(SystemInfo::DailyVoiceUrl).toString();
911 logversion = installInfo.revision();
913 else {
914 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
915 logversion = installInfo.release();
917 if(QMessageBox::question(this, tr("Confirm Installation"),
918 tr("Do you really want to install the voice file?"),
919 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
920 return;
922 QDate date = QDate::fromString(
923 ServerInfo::value(ServerInfo::DailyDate).toString(), Qt::ISODate);
924 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
925 // replace placeholder in voice url
926 voiceurl.replace("%DATE%", date.toString("yyyyMMdd"));
927 voiceurl.replace("%MODEL%", model);
928 voiceurl.replace("%RELVERSION%", relversion);
930 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
932 // create logger
933 logger = new ProgressLoggerGui(this);
934 logger->show();
935 // create zip installer
936 installer = new ZipInstaller(this);
938 installer->setUrl(voiceurl);
939 installer->setLogSection("Voice");
940 installer->setLogVersion(logversion);
941 installer->setMountPoint(mountpoint);
942 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
943 installer->setCache(true);
944 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
945 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
946 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
947 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
948 installer->install();
952 void RbUtilQt::installDoomBtn()
954 if(chkConfig(this)) return;
955 if(!hasDoom()){
956 QMessageBox::critical(this, tr("Error"),
957 tr("Your device doesn't have a doom plugin. Aborting."));
958 return;
961 if(QMessageBox::question(this, tr("Confirm Installation"),
962 tr("Do you really want to install the game addon files?"),
963 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
964 // create logger
965 logger = new ProgressLoggerGui(this);
966 logger->show();
968 installDoom();
970 bool RbUtilQt::installDoomAuto()
972 installDoom();
973 return !m_error;
976 bool RbUtilQt::hasDoom()
978 QFile doomrock(RbSettings::value(RbSettings::Mountpoint).toString()
979 +"/.rockbox/rocks/games/doom.rock");
980 return doomrock.exists();
983 void RbUtilQt::installDoom()
985 // create zip installer
986 installer = new ZipInstaller(this);
988 installer->setUrl(SystemInfo::value(SystemInfo::DoomUrl).toString());
989 installer->setLogSection("Game Addons");
990 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
991 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
992 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
993 installer->setCache(true);
994 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
995 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
996 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
997 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
998 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
999 installer->install();
1003 void RbUtilQt::installThemes()
1005 if(chkConfig(this)) return;
1006 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
1007 tw->setModal(true);
1008 tw->show();
1011 void RbUtilQt::createTalkFiles(void)
1013 if(chkConfig(this)) return;
1014 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
1015 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
1016 installWindow->show();
1020 void RbUtilQt::createVoiceFile(void)
1022 if(chkConfig(this)) return;
1023 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
1025 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
1026 installWindow->show();
1029 void RbUtilQt::uninstall(void)
1031 if(chkConfig(this)) return;
1032 UninstallWindow *uninstallWindow = new UninstallWindow(this);
1033 uninstallWindow->show();
1037 void RbUtilQt::uninstallBootloader(void)
1039 if(chkConfig(this)) return;
1040 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
1041 tr("Do you really want to uninstall the Bootloader?"),
1042 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
1043 // create logger
1044 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1045 logger->setProgressVisible(false);
1046 logger->show();
1048 QString platform = RbSettings::value(RbSettings::Platform).toString();
1050 // create installer
1051 BootloaderInstallBase *bl = BootloaderInstallBase::createBootloaderInstaller(this,
1052 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
1054 if(bl == NULL ) {
1055 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
1056 logger->setFinished();
1057 return;
1059 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
1060 QStringList blfilepath;
1061 for(int a = 0; a < blfile.size(); a++) {
1062 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
1063 + blfile.at(a));
1065 bl->setBlFile(blfilepath);
1067 BootloaderInstallBase::BootloaderType currentbl = bl->installed();
1068 if((bl->capabilities() & BootloaderInstallBase::Uninstall) == 0
1069 || currentbl == BootloaderInstallBase::BootloaderUnknown
1070 || currentbl == BootloaderInstallBase::BootloaderOther)
1072 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target. "
1073 "Try a normal firmware update to remove the booloader."), LOGERROR);
1074 logger->setFinished();
1075 delete bl;
1076 return;
1079 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1080 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1082 bl->uninstall();
1084 logger->setFinished();
1089 void RbUtilQt::installPortable(void)
1091 if(QMessageBox::question(this, tr("Confirm installation"),
1092 tr("Do you really want to install Rockbox Utility to your player? "
1093 "After installation you can run it from the players hard drive."),
1094 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1095 return;
1097 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1098 logger->setProgressMax(0);
1099 logger->setProgressValue(0);
1100 logger->show();
1101 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
1103 // check mountpoint
1104 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
1105 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
1106 logger->setFinished();
1107 return;
1110 // remove old files first.
1111 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1112 + "/RockboxUtility.exe");
1113 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1114 + "/RockboxUtility.ini");
1115 // copy currently running binary and currently used settings file
1116 if(!QFile::copy(qApp->applicationFilePath(),
1117 RbSettings::value(RbSettings::Mountpoint).toString()
1118 + "/RockboxUtility.exe")) {
1119 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
1120 logger->setFinished();
1121 return;
1123 logger->addItem(tr("Installing user configuration"), LOGINFO);
1124 if(!QFile::copy(RbSettings::userSettingFilename(),
1125 RbSettings::value(RbSettings::Mountpoint).toString()
1126 + "/RockboxUtility.ini")) {
1127 logger->addItem(tr("Error installing user configuration"), LOGERROR);
1128 logger->setFinished();
1129 return;
1131 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
1132 logger->setFinished();
1133 logger->setProgressMax(1);
1134 logger->setProgressValue(1);
1139 QUrl RbUtilQt::proxy()
1141 QUrl proxy;
1142 if(RbSettings::value(RbSettings::ProxyType) == "manual")
1143 proxy.setEncodedUrl(RbSettings::value(RbSettings::Proxy).toByteArray());
1144 else if(RbSettings::value(RbSettings::ProxyType) == "system")
1145 proxy = System::systemProxy();
1146 qDebug() << proxy.userName() << proxy.password() << proxy.host() << proxy.port();
1147 return proxy;
1151 bool RbUtilQt::chkConfig(QWidget *parent)
1153 bool error = false;
1154 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
1155 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
1156 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
1157 error = true;
1159 if(parent) QMessageBox::critical(parent, tr("Configuration error"),
1160 tr("Your configuration is invalid. Please go to the configuration "
1161 "dialog and make sure the selected values are correct."));
1163 return error;
1166 void RbUtilQt::checkUpdate(void)
1168 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1169 #if defined(Q_OS_WIN32)
1170 url += "win32/";
1171 #elif defined(Q_OS_LINUX)
1172 url += "linux/";
1173 #elif defined(Q_OS_MACX)
1174 url += "macosx/";
1175 #endif
1177 update = new HttpGet(this);
1178 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
1179 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
1180 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1181 update->setCache(true);
1183 ui.statusbar->showMessage(tr("Checking for update ..."));
1184 update->getFile(QUrl(url));
1187 void RbUtilQt::downloadUpdateDone(bool error)
1189 if(error) {
1190 qDebug() << "[RbUtil] network error:" << update->error();
1192 else {
1193 QString toParse(update->readAll());
1195 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
1196 QStringList rbutilList;
1197 int pos = 0;
1198 while ((pos = searchString.indexIn(toParse, pos)) != -1)
1200 rbutilList << searchString.cap(1);
1201 pos += searchString.matchedLength();
1203 qDebug() << "[RbUtilQt] Checking for update";
1205 QString newVersion = "";
1206 QString foundVersion = "";
1207 // check if there is a binary with higher version in this list
1208 for(int i=0; i < rbutilList.size(); i++)
1210 QString item = rbutilList.at(i);
1211 #if defined(Q_OS_LINUX)
1212 #if defined(__amd64__)
1213 // skip if it isn't a 64 bit build
1214 if( !item.contains("64bit"))
1215 continue;
1216 // strip the "64bit" suffix for comparison
1217 item = item.remove("64bit");
1218 #else
1219 //skip if it is a 64bit build
1220 if(item.contains("64bit"))
1221 continue;
1222 #endif
1223 #endif
1224 // check if it is newer, and remember newest
1225 if(Utils::compareVersionStrings(VERSION, item) == 1)
1227 if(Utils::compareVersionStrings(newVersion, item) == 1)
1229 newVersion = item;
1230 foundVersion = rbutilList.at(i);
1235 // if we found something newer, display info
1236 if(foundVersion != "")
1238 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1239 #if defined(Q_OS_WIN32)
1240 url += "win32/";
1241 #elif defined(Q_OS_LINUX)
1242 url += "linux/";
1243 #elif defined(Q_OS_MACX)
1244 url += "macosx/";
1245 #endif
1246 url += foundVersion;
1248 QMessageBox::information(this,tr("RockboxUtility Update available"),
1249 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1250 "Download it from here: <a href='%1'>%2</a>")
1251 .arg(url).arg(foundVersion));
1252 ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
1254 else {
1255 ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
1261 void RbUtilQt::changeEvent(QEvent *e)
1263 if(e->type() == QEvent::LanguageChange) {
1264 ui.retranslateUi(this);
1265 buildInfo.open();
1266 ServerInfo::readBuildInfo(buildInfo.fileName());
1267 buildInfo.close();
1268 updateDevice();
1269 } else {
1270 QMainWindow::changeEvent(e);