Replaygain pre-amp can be set in 0.5 dB steps.
[kugel-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blob135e5100d47cc1060208f4c1e31cde28e8d4bcf8
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 "installwindow.h"
28 #include "installtalkwindow.h"
29 #include "createvoicewindow.h"
30 #include "httpget.h"
31 #include "themesinstallwindow.h"
32 #include "uninstallwindow.h"
33 #include "utils.h"
34 #include "rockboxinfo.h"
35 #include "rbzip.h"
36 #include "sysinfo.h"
37 #include "system.h"
38 #include "systrace.h"
39 #include "rbsettings.h"
40 #include "serverinfo.h"
41 #include "systeminfo.h"
43 #include "progressloggerinterface.h"
45 #include "bootloaderinstallbase.h"
46 #include "bootloaderinstallmi4.h"
47 #include "bootloaderinstallhex.h"
48 #include "bootloaderinstallipod.h"
49 #include "bootloaderinstallsansa.h"
50 #include "bootloaderinstallfile.h"
51 #include "bootloaderinstallchinachip.h"
52 #include "bootloaderinstallams.h"
53 #include "bootloaderinstalltcc.h"
56 #if defined(Q_OS_LINUX)
57 #include <stdio.h>
58 #endif
59 #if defined(Q_OS_WIN32)
60 #if defined(UNICODE)
61 #define _UNICODE
62 #endif
63 #include <stdio.h>
64 #include <tchar.h>
65 #include <windows.h>
66 #endif
68 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
70 // startup log
71 qDebug() << "======================================";
72 qDebug() << "[System] Rockbox Utility " VERSION;
73 qDebug() << "[System] Qt version:" << qVersion();
74 qDebug() << "======================================";
76 absolutePath = qApp->applicationDirPath();
78 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
79 // init startup & autodetection
80 ui.setupUi(this);
81 #if defined(Q_OS_LINUX)
82 QIcon windowIcon(":/icons/rockbox-clef.svg");
83 this->setWindowIcon(windowIcon);
84 #endif
86 #if defined(Q_OS_WIN32)
87 long ret;
88 HKEY hk;
89 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Wine"),
90 0, KEY_QUERY_VALUE, &hk);
91 if(ret == ERROR_SUCCESS) {
92 QMessageBox::warning(this, tr("Wine detected!"),
93 tr("It seems you are trying to run this program under Wine. "
94 "Please don't do this, running under Wine will fail. "
95 "Use the native Linux binary instead."),
96 QMessageBox::Ok, QMessageBox::Ok);
97 qDebug() << "[RbUtil] WINE DETECTED!";
98 RegCloseKey(hk);
100 #endif
101 downloadInfo();
103 m_gotInfo = false;
104 m_auto = false;
106 // manual tab
107 ui.radioPdf->setChecked(true);
109 // info tab
110 ui.treeInfo->setAlternatingRowColors(true);
111 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
112 ui.treeInfo->expandAll();
113 ui.treeInfo->setColumnCount(2);
114 ui.treeInfo->setLayoutDirection(Qt::LeftToRight);
115 // disable quick install until version info is available
116 ui.buttonSmall->setEnabled(false);
117 ui.buttonComplete->setEnabled(false);
118 ui.actionSmall_Installation->setEnabled(false);
119 ui.actionComplete_Installation->setEnabled(false);
121 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
122 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
123 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
124 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
125 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
126 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
127 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
128 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
129 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
130 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
131 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
132 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
133 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
134 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
135 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
136 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
137 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
138 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
139 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
140 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
142 // actions accessible from the menu
143 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
144 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
145 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
146 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
147 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
148 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
149 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
150 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
151 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
152 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
153 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
154 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
155 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
156 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
158 #if !defined(STATIC)
159 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
160 #else
161 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
162 #endif
167 void RbUtilQt::shutdown(void)
169 // restore default message handler to prevent trace accesses during
170 // object destruction -- the trace object could already be destroyed.
171 // Fixes segfaults on exit.
172 qInstallMsgHandler(0);
173 SysTrace::save();
174 this->close();
178 void RbUtilQt::trace(void)
180 SysTrace wnd(this);
181 wnd.exec();
184 void RbUtilQt::sysinfo(void)
186 Sysinfo info(this);
187 info.exec();
190 void RbUtilQt::updateTabs(int count)
192 switch(count) {
193 case 6:
194 updateInfo();
195 break;
196 default:
197 break;
202 void RbUtilQt::downloadInfo()
204 // try to get the current build information
205 daily = new HttpGet(this);
206 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
207 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
208 if(RbSettings::value(RbSettings::CacheOffline).toBool())
209 daily->setCache(true);
210 else
211 daily->setCache(false);
212 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
213 qDebug() << "[RbUtil] downloading build info";
214 daily->setFile(&buildInfo);
215 daily->getFile(QUrl(SystemInfo::value(SystemInfo::ServerConfUrl).toString()));
219 void RbUtilQt::downloadDone(bool error)
221 if(error) {
222 qDebug() << "[RbUtil] network error:" << daily->error();
223 ui.statusbar->showMessage(tr("Can't get version information!"));
224 QMessageBox::critical(this, tr("Network error"),
225 tr("Can't get version information.\n"
226 "Network error: %1. Please check your network and proxy settings.")
227 .arg(daily->errorString()));
228 return;
230 qDebug() << "[RbUtil] network status:" << daily->error();
232 // read info into ServerInfo object
233 buildInfo.open();
234 ServerInfo::readBuildInfo(buildInfo.fileName());
235 buildInfo.close();
237 // start bleeding info download
238 bleeding = new HttpGet(this);
239 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
240 connect(qApp, SIGNAL(lastWindowClosed()), bleeding, SLOT(abort()));
241 if(RbSettings::value(RbSettings::CacheOffline).toBool())
242 bleeding->setCache(true);
243 bleeding->setFile(&bleedingInfo);
244 bleeding->getFile(QUrl(SystemInfo::value(SystemInfo::BleedingInfo).toString()));
245 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
250 void RbUtilQt::downloadBleedingDone(bool error)
252 if(error) {
253 qDebug() << "[RbUtil] network error:" << bleeding->error();
254 ui.statusbar->showMessage(tr("Can't get version information!"));
255 QMessageBox::critical(this, tr("Network error"),
256 tr("Can't get version information.\n"
257 "Network error: %1. Please check your network and proxy settings.")
258 .arg(bleeding->errorString()));
259 return;
261 else {
262 bleedingInfo.open();
263 ServerInfo::readBleedingInfo(bleedingInfo.fileName());
264 bleedingInfo.close();
266 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
267 updateSettings();
268 m_gotInfo = true;
270 //start check for updates
271 checkUpdate();
276 void RbUtilQt::about()
278 QDialog *window = new QDialog(this);
279 Ui::aboutBox about;
280 about.setupUi(window);
281 window->setLayoutDirection(Qt::LeftToRight);
282 window->setModal(true);
284 QFile licence(":/docs/gpl-2.0.html");
285 licence.open(QIODevice::ReadOnly);
286 QTextStream c(&licence);
287 QString cline = c.readAll();
288 about.browserLicense->insertHtml(cline);
289 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
290 QFile credits(":/docs/CREDITS");
291 credits.open(QIODevice::ReadOnly);
292 QTextStream r(&credits);
293 r.setCodec(QTextCodec::codecForName("UTF-8"));
294 while(!r.atEnd()) {
295 QString line = r.readLine();
296 // filter out header.
297 line.remove(QRegExp("^[^A-Z]+.*"));
298 line.remove(QRegExp("^People.*"));
299 about.browserCredits->append(line);
301 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
302 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
303 about.labelTitle->setText(title);
305 window->show();
310 void RbUtilQt::help()
312 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
313 QDesktopServices::openUrl(helpurl);
317 void RbUtilQt::configDialog()
319 Config *cw = new Config(this);
320 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
321 cw->show();
325 void RbUtilQt::updateSettings()
327 qDebug() << "[RbUtil] updating current settings";
328 updateDevice();
329 updateManual();
330 if(RbSettings::value(RbSettings::ProxyType) == "system") {
331 HttpGet::setGlobalProxy(System::systemProxy());
333 else if(RbSettings::value(RbSettings::ProxyType) == "manual") {
334 HttpGet::setGlobalProxy(RbSettings::value(RbSettings::Proxy).toString());
336 else {
337 HttpGet::setGlobalProxy(QUrl(""));
339 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
340 HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
342 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
343 QApplication::processEvents();
344 QMessageBox::information(this, tr("New installation"),
345 tr("This is a new installation of Rockbox Utility, or a new version. "
346 "The configuration dialog will now open to allow you to setup the program, "
347 " or review your settings."));
348 configDialog();
350 else if(chkConfig(false)) {
351 QApplication::processEvents();
352 QMessageBox::critical(this, tr("Configuration error"),
353 tr("Your configuration is invalid. This is most likely due "
354 "to a changed device path. The configuration dialog will "
355 "now open to allow you to correct the problem."));
356 configDialog();
361 void RbUtilQt::updateDevice()
363 /* TODO: We should check the flags of the bootloaderinstall classes, and not
364 * just check if its != none or != "fwpatcher" */
366 /* Enable bootloader installation, if possible */
367 bool bootloaderInstallable =
368 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
369 ui.buttonBootloader->setEnabled(bootloaderInstallable);
370 ui.labelBootloader->setEnabled(bootloaderInstallable);
371 ui.actionInstall_Bootloader->setEnabled(bootloaderInstallable);
373 /* Enable bootloader uninstallation, if possible */
374 bool bootloaderUninstallable = bootloaderInstallable &&
375 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
376 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
377 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
378 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
380 /* Disable the whole tab widget if configuration is invalid */
381 bool configurationValid = !chkConfig(false);
382 ui.tabWidget->setEnabled(configurationValid);
383 ui.menuA_ctions->setEnabled(configurationValid);
385 // displayed device info
386 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
387 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
388 QString name = SystemInfo::value(SystemInfo::CurName).toString() +
389 " (" + ServerInfo::value(ServerInfo::CurStatus).toString() + ")";
390 if(name.isEmpty()) name = "&lt;none&gt;";
391 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
392 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
393 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
395 // hide quickstart buttons if no release available
396 bool installable = !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty();
397 ui.buttonSmall->setEnabled(installable);
398 ui.buttonComplete->setEnabled(installable);
399 ui.actionSmall_Installation->setEnabled(installable);
400 ui.actionComplete_Installation->setEnabled(installable);
404 void RbUtilQt::updateManual()
406 if(RbSettings::value(RbSettings::Platform) != "")
408 QString manual= SystemInfo::value(SystemInfo::CurManual).toString();
410 if(manual == "")
411 manual = "rockbox-"
412 + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
413 QString pdfmanual;
414 pdfmanual = SystemInfo::value(SystemInfo::ManualUrl).toString()
415 + "/" + manual + ".pdf";
416 QString htmlmanual;
417 htmlmanual = SystemInfo::value(SystemInfo::ManualUrl).toString()
418 + "/" + manual + "/rockbox-build.html";
419 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
420 .arg(pdfmanual));
421 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
422 .arg(htmlmanual));
424 else {
425 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
426 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
427 .arg("http://www.rockbox.org/manual.shtml"));
432 void RbUtilQt::completeInstall()
434 if(chkConfig(true)) return;
435 if(QMessageBox::question(this, tr("Confirm Installation"),
436 tr("Do you really want to perform a complete installation?\n\n"
437 "This will install Rockbox %1. To install the most recent "
438 "development build available press \"Cancel\" and "
439 "use the \"Installation\" tab.")
440 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
441 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
442 return;
443 // create logger
444 logger = new ProgressLoggerGui(this);
445 logger->show();
447 if(smallInstallInner())
448 return;
449 logger->setRunning();
450 // Fonts
451 m_error = false;
452 m_installed = false;
453 if(!installFontsAuto())
454 return;
455 else
457 // wait for installation finished
458 while(!m_installed)
459 QApplication::processEvents();
461 if(m_error) return;
462 logger->setRunning();
464 // Doom
465 if(hasDoom())
467 m_error = false;
468 m_installed = false;
469 if(!installDoomAuto())
470 return;
471 else
473 // wait for installation finished
474 while(!m_installed)
475 QApplication::processEvents();
477 if(m_error) return;
480 // theme
481 // this is a window
482 // it has its own logger window,so close our.
483 logger->close();
484 installThemes();
488 void RbUtilQt::smallInstall()
490 if(chkConfig(true)) return;
491 if(QMessageBox::question(this, tr("Confirm Installation"),
492 tr("Do you really want to perform a minimal installation? "
493 "A minimal installation will contain only the absolutely "
494 "necessary parts to run Rockbox.\n\n"
495 "This will install Rockbox %1. To install the most recent "
496 "development build available press \"Cancel\" and "
497 "use the \"Installation\" tab.")
498 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
499 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
500 return;
502 // create logger
503 logger = new ProgressLoggerGui(this);
504 logger->show();
506 smallInstallInner();
509 bool RbUtilQt::smallInstallInner()
511 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
512 // show dialog with error if mount point is wrong
513 if(!QFileInfo(mountpoint).isDir()) {
514 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
515 logger->setFinished();
516 return true;
518 // Bootloader
519 if(SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none")
521 m_error = false;
522 m_installed = false;
523 m_auto = true;
524 if(!installBootloaderAuto()) {
525 logger->setFinished();
526 return true;
528 else
530 // wait for boot loader installation finished
531 while(!m_installed)
532 QApplication::processEvents();
534 m_auto = false;
535 if(m_error) return true;
536 logger->setRunning();
539 // Rockbox
540 m_error = false;
541 m_installed = false;
542 if(!installAuto())
543 return true;
544 else
546 // wait for installation finished
547 while(!m_installed)
548 QApplication::processEvents();
551 installBootloaderPost(false);
552 return false;
555 void RbUtilQt::installdone(bool error)
557 qDebug() << "[RbUtil] install done";
558 m_installed = true;
559 m_error = error;
562 void RbUtilQt::installBtn()
564 if(chkConfig(true)) return;
565 install();
568 bool RbUtilQt::installAuto()
570 QString file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
571 file.replace("%MODEL%", SystemInfo::value(SystemInfo::CurBuildserverModel).toString());
572 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
574 // check installed Version and Target
575 QString warning = Utils::checkEnvironment(false);
576 if(!warning.isEmpty())
578 if(QMessageBox::warning(this, tr("Really continue?"), warning,
579 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
580 == QMessageBox::Abort)
582 logger->addItem(tr("Aborted!"), LOGERROR);
583 logger->setFinished();
584 return false;
588 // check version
589 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
590 if(rbinfo.version() != "")
592 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
593 tr("Rockbox installation detected. Do you want to backup first?"),
594 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
596 logger->addItem(tr("Starting backup..."),LOGINFO);
597 QString backupName = RbSettings::value(RbSettings::Mountpoint).toString()
598 + "/.backup/rockbox-backup-" + rbinfo.version() + ".zip";
600 //! create dir, if it doesnt exist
601 QFileInfo backupFile(backupName);
602 if(!QDir(backupFile.path()).exists())
604 QDir a;
605 a.mkpath(backupFile.path());
608 //! create backup
609 RbZip backup;
610 connect(&backup,SIGNAL(zipProgress(int,int)),logger, SLOT(setProgress(int,int)));
611 if(backup.createZip(backupName,
612 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
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(true)) 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;
677 QString type = SystemInfo::value(SystemInfo::CurBootloaderMethod).toString();
678 if(type == "mi4") {
679 bl = new BootloaderInstallMi4(this);
681 else if(type == "hex") {
682 bl = new BootloaderInstallHex(this);
684 else if(type == "sansa") {
685 bl = new BootloaderInstallSansa(this);
687 else if(type == "ipod") {
688 bl = new BootloaderInstallIpod(this);
690 else if(type == "file") {
691 bl = new BootloaderInstallFile(this);
693 else if(type == "chinachip") {
694 bl = new BootloaderInstallChinaChip(this);
696 else if(type == "ams") {
697 bl = new BootloaderInstallAms(this);
699 else if(type == "tcc") {
700 bl = new BootloaderInstallTcc(this);
702 else {
703 logger->addItem(tr("No install method known."), LOGERROR);
704 logger->setFinished();
705 return;
708 // set bootloader filename. Do this now as installed() needs it.
709 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
710 QStringList blfilepath;
711 for(int a = 0; a < blfile.size(); a++) {
712 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
713 + blfile.at(a));
715 bl->setBlFile(blfilepath);
716 QUrl url(SystemInfo::value(SystemInfo::BootloaderUrl).toString()
717 + SystemInfo::value(SystemInfo::CurBootloaderName).toString());
718 bl->setBlUrl(url);
719 bl->setLogfile(RbSettings::value(RbSettings::Mountpoint).toString()
720 + "/.rockbox/rbutil.log");
722 if(bl->installed() == BootloaderInstallBase::BootloaderRockbox) {
723 if(QMessageBox::question(this, tr("Bootloader detected"),
724 tr("Bootloader already installed. Do you want to reinstall the bootloader?"),
725 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
726 if(m_auto) {
727 // keep logger open for auto installs.
728 // don't consider abort as error in auto-mode.
729 logger->addItem(tr("Bootloader installation skipped"), LOGINFO);
730 installBootloaderPost(false);
732 else {
733 logger->close();
734 installBootloaderPost(true);
736 delete bl;
737 return;
740 else if(bl->installed() == BootloaderInstallBase::BootloaderOther
741 && bl->capabilities() & BootloaderInstallBase::Backup)
743 QString targetFolder = SystemInfo::value(SystemInfo::CurPlatformName).toString()
744 + " Firmware Backup";
745 // remove invalid character(s)
746 targetFolder.remove(QRegExp("[:/]"));
747 if(QMessageBox::question(this, tr("Create Bootloader backup"),
748 tr("You can create a backup of the original bootloader "
749 "file. Press \"Yes\" to select an output folder on your "
750 "computer to save the file to. The file will get placed "
751 "in a new folder \"%1\" created below the selected folder.\n"
752 "Press \"No\" to skip this step.").arg(targetFolder),
753 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
754 backupDestination = QFileDialog::getExistingDirectory(this,
755 tr("Browse backup folder"), QDir::homePath());
756 if(!backupDestination.isEmpty())
757 backupDestination += "/" + targetFolder;
759 qDebug() << "[RbUtil] backing up to" << backupDestination;
760 // backup needs to be done after the logger has been set up.
764 if(bl->capabilities() & BootloaderInstallBase::NeedsOf)
766 int ret;
767 ret = QMessageBox::information(this, tr("Prerequisites"),
768 bl->ofHint(),QMessageBox::Ok | QMessageBox::Abort);
769 if(ret != QMessageBox::Ok) {
770 // consider aborting an error to close window / abort automatic
771 // installation.
772 m_error = true;
773 logger->addItem(tr("Bootloader installation aborted"), LOGINFO);
774 logger->setFinished();
775 return;
777 // open dialog to browse to of file
778 QString offile;
779 offile = QFileDialog::getOpenFileName(this,
780 tr("Select firmware file"), QDir::homePath());
781 if(!QFileInfo(offile).isReadable()) {
782 logger->addItem(tr("Error opening firmware file"), LOGERROR);
783 logger->setFinished();
784 m_error = true;
785 return;
787 bl->setOfFile(offile);
790 // the bootloader install class does NOT use any GUI stuff.
791 // All messages are passed via signals.
792 connect(bl, SIGNAL(done(bool)), logger, SLOT(setFinished()));
793 connect(bl, SIGNAL(done(bool)), this, SLOT(installBootloaderPost(bool)));
794 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
795 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
797 // start install.
798 if(!backupDestination.isEmpty()) {
799 if(!bl->backup(backupDestination)) {
800 if(QMessageBox::warning(this, tr("Backup error"),
801 tr("Could not create backup file. Continue?"),
802 QMessageBox::No | QMessageBox::Yes)
803 == QMessageBox::No) {
804 logger->setFinished();
805 return;
809 bl->install();
812 void RbUtilQt::installBootloaderPost(bool error)
814 qDebug() << "[RbUtil] Bootloader Post-Installation, error state:" << error;
815 // if an error occured don't perform post install steps.
816 if(error) {
817 m_error = true;
818 return;
820 else
821 m_error = false;
823 m_installed = true;
824 // end here if automated install
825 if(m_auto)
826 return;
828 QString msg = BootloaderInstallBase::postinstallHints(
829 RbSettings::value(RbSettings::Platform).toString());
830 if(!msg.isEmpty()) {
831 QMessageBox::information(this, tr("Manual steps required"), msg);
832 logger->close();
837 void RbUtilQt::installFontsBtn()
839 if(chkConfig(true)) return;
840 if(QMessageBox::question(this, tr("Confirm Installation"),
841 tr("Do you really want to install the fonts package?"),
842 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
843 // create logger
844 logger = new ProgressLoggerGui(this);
845 logger->show();
846 installFonts();
849 bool RbUtilQt::installFontsAuto()
851 installFonts();
853 return !m_error;
856 void RbUtilQt::installFonts()
858 // create zip installer
859 installer = new ZipInstaller(this);
861 installer->setUrl(SystemInfo::value(SystemInfo::FontUrl).toString());
862 installer->setLogSection("Fonts");
863 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
864 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
865 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
866 installer->setCache(true);
868 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
869 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
870 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
871 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
872 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
873 installer->install();
877 void RbUtilQt::installVoice()
879 if(chkConfig(true)) return;
881 if(m_gotInfo == false)
883 QMessageBox::warning(this, tr("Warning"),
884 tr("The Application is still downloading Information about new Builds."
885 " Please try again shortly."));
886 return;
889 if(QMessageBox::question(this, tr("Confirm Installation"),
890 tr("Do you really want to install the voice file?"),
891 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
892 // create logger
893 logger = new ProgressLoggerGui(this);
894 logger->show();
896 // create zip installer
897 installer = new ZipInstaller(this);
899 QString voiceurl = SystemInfo::value(SystemInfo::VoiceUrl).toString();
900 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
901 voiceurl += SystemInfo::value(SystemInfo::CurBuildserverModel).toString() + "-" +
902 date.toString("yyyyMMdd") + "-english.zip";
903 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
905 installer->setUrl(voiceurl);
906 installer->setLogSection("Voice");
907 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
908 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
909 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
910 installer->setCache(true);
911 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
912 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
913 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
914 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
915 installer->install();
919 void RbUtilQt::installDoomBtn()
921 if(chkConfig(true)) return;
922 if(!hasDoom()){
923 QMessageBox::critical(this, tr("Error"),
924 tr("Your device doesn't have a doom plugin. Aborting."));
925 return;
928 if(QMessageBox::question(this, tr("Confirm Installation"),
929 tr("Do you really want to install the game addon files?"),
930 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
931 // create logger
932 logger = new ProgressLoggerGui(this);
933 logger->show();
935 installDoom();
937 bool RbUtilQt::installDoomAuto()
939 installDoom();
940 return !m_error;
943 bool RbUtilQt::hasDoom()
945 QFile doomrock(RbSettings::value(RbSettings::Mountpoint).toString()
946 +"/.rockbox/rocks/games/doom.rock");
947 return doomrock.exists();
950 void RbUtilQt::installDoom()
952 // create zip installer
953 installer = new ZipInstaller(this);
955 installer->setUrl(SystemInfo::value(SystemInfo::DoomUrl).toString());
956 installer->setLogSection("Game Addons");
957 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
958 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
959 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
960 installer->setCache(true);
961 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
962 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
963 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
964 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
965 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
966 installer->install();
970 void RbUtilQt::installThemes()
972 if(chkConfig(true)) return;
973 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
974 tw->setModal(true);
975 tw->show();
978 void RbUtilQt::createTalkFiles(void)
980 if(chkConfig(true)) return;
981 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
982 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
983 installWindow->show();
987 void RbUtilQt::createVoiceFile(void)
989 if(chkConfig(true)) return;
990 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
992 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
993 installWindow->show();
996 void RbUtilQt::uninstall(void)
998 if(chkConfig(true)) return;
999 UninstallWindow *uninstallWindow = new UninstallWindow(this);
1000 uninstallWindow->show();
1004 void RbUtilQt::uninstallBootloader(void)
1006 if(chkConfig(true)) return;
1007 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
1008 tr("Do you really want to uninstall the Bootloader?"),
1009 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
1010 // create logger
1011 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1012 logger->setProgressVisible(false);
1013 logger->show();
1015 QString platform = RbSettings::value(RbSettings::Platform).toString();
1017 // create installer
1018 BootloaderInstallBase *bl;
1019 QString type = SystemInfo::value(SystemInfo::CurBootloaderMethod).toString();
1020 if(type == "mi4") {
1021 bl = new BootloaderInstallMi4(this);
1023 else if(type == "hex") {
1024 bl = new BootloaderInstallHex(this);
1026 else if(type == "sansa") {
1027 bl = new BootloaderInstallSansa(this);
1029 else if(type == "ipod") {
1030 bl = new BootloaderInstallIpod(this);
1032 else if(type == "file") {
1033 bl = new BootloaderInstallFile(this);
1035 else {
1036 logger->addItem(tr("No uninstall method known."), LOGERROR);
1037 logger->setFinished();
1038 return;
1041 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
1042 QStringList blfilepath;
1043 for(int a = 0; a < blfile.size(); a++) {
1044 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
1045 + blfile.at(a));
1047 bl->setBlFile(blfilepath);
1049 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1050 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1052 int result;
1053 result = bl->uninstall();
1055 logger->setFinished();
1060 void RbUtilQt::downloadManual(void)
1062 if(chkConfig(true)) return;
1063 if(QMessageBox::question(this, tr("Confirm download"),
1064 tr("Do you really want to download the manual? The manual will be saved "
1065 "to the root folder of your player."),
1066 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1067 return;
1069 QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
1070 if(manual.isEmpty())
1071 manual = "rockbox-"
1072 + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
1074 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
1076 QString manualurl;
1077 QString target;
1078 QString section;
1079 if(ui.radioPdf->isChecked()) {
1080 target = "/" + manual + ".pdf";
1081 section = "Manual (PDF)";
1083 else {
1084 target = "/" + manual + "-" + date.toString("yyyyMMdd") + "-html.zip";
1085 section = "Manual (HTML)";
1087 manualurl = SystemInfo::value(SystemInfo::ManualUrl).toString() + "/" + target;
1088 qDebug() << "[RbUtil] Manual URL:" << manualurl;
1090 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1091 logger->show();
1092 installer = new ZipInstaller(this);
1093 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
1094 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
1095 installer->setCache(true);
1096 installer->setLogSection(section);
1097 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
1098 installer->setUrl(manualurl);
1099 installer->setUnzip(false);
1100 installer->setTarget(target);
1101 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1102 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1103 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
1104 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
1105 installer->install();
1109 void RbUtilQt::installPortable(void)
1111 if(QMessageBox::question(this, tr("Confirm installation"),
1112 tr("Do you really want to install Rockbox Utility to your player? "
1113 "After installation you can run it from the players hard drive."),
1114 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1115 return;
1117 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1118 logger->setProgressMax(0);
1119 logger->setProgressValue(0);
1120 logger->show();
1121 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
1123 // check mountpoint
1124 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
1125 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
1126 logger->setFinished();
1127 return;
1130 // remove old files first.
1131 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1132 + "/RockboxUtility.exe");
1133 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1134 + "/RockboxUtility.ini");
1135 // copy currently running binary and currently used settings file
1136 if(!QFile::copy(qApp->applicationFilePath(),
1137 RbSettings::value(RbSettings::Mountpoint).toString()
1138 + "/RockboxUtility.exe")) {
1139 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
1140 logger->setFinished();
1141 return;
1143 logger->addItem(tr("Installing user configuration"), LOGINFO);
1144 if(!QFile::copy(RbSettings::userSettingFilename(),
1145 RbSettings::value(RbSettings::Mountpoint).toString()
1146 + "/RockboxUtility.ini")) {
1147 logger->addItem(tr("Error installing user configuration"), LOGERROR);
1148 logger->setFinished();
1149 return;
1151 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
1152 logger->setFinished();
1153 logger->setProgressMax(1);
1154 logger->setProgressValue(1);
1159 void RbUtilQt::updateInfo()
1161 qDebug() << "[RbUtil] updating server info";
1163 QSettings log(RbSettings::value(RbSettings::Mountpoint).toString()
1164 + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
1165 QStringList groups = log.childGroups();
1166 QList<QTreeWidgetItem *> items;
1167 QTreeWidgetItem *w, *w2;
1168 QString min, max;
1169 int olditems = 0;
1171 // remove old list entries (if any)
1172 int l = ui.treeInfo->topLevelItemCount();
1173 while(l--) {
1174 QTreeWidgetItem *m;
1175 m = ui.treeInfo->takeTopLevelItem(l);
1176 // delete childs (single level deep, no recursion here)
1177 int n = m->childCount();
1178 while(n--)
1179 delete m->child(n);
1181 // get and populate new items
1182 for(int a = 0; a < groups.size(); a++) {
1183 log.beginGroup(groups.at(a));
1184 QStringList keys = log.allKeys();
1185 w = new QTreeWidgetItem;
1186 w->setFlags(Qt::ItemIsEnabled);
1187 w->setText(0, groups.at(a));
1188 items.append(w);
1189 // get minimum and maximum version information so we can hilight old files
1190 min = max = log.value(keys.at(0)).toString();
1191 for(int b = 0; b < keys.size(); b++) {
1192 if(log.value(keys.at(b)).toString() > max)
1193 max = log.value(keys.at(b)).toString();
1194 if(log.value(keys.at(b)).toString() < min)
1195 min = log.value(keys.at(b)).toString();
1198 for(int b = 0; b < keys.size(); b++) {
1199 QString file;
1200 file = RbSettings::value(RbSettings::Mountpoint).toString() + "/" + keys.at(b);
1201 if(QFileInfo(file).isDir())
1202 continue;
1203 w2 = new QTreeWidgetItem(w, QStringList() << "/"
1204 + keys.at(b) << log.value(keys.at(b)).toString());
1205 if(log.value(keys.at(b)).toString() != max) {
1206 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
1207 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
1208 olditems++;
1210 items.append(w2);
1212 log.endGroup();
1213 if(min != max)
1214 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
1215 else
1216 w->setData(1, Qt::DisplayRole, max);
1218 ui.treeInfo->insertTopLevelItems(0, items);
1219 ui.treeInfo->resizeColumnToContents(0);
1223 QUrl RbUtilQt::proxy()
1225 if(RbSettings::value(RbSettings::ProxyType) == "manual")
1226 return QUrl(RbSettings::value(RbSettings::Proxy).toString());
1227 else if(RbSettings::value(RbSettings::ProxyType) == "system")
1228 return System::systemProxy();
1229 return QUrl("");
1233 bool RbUtilQt::chkConfig(bool warn)
1235 bool error = false;
1236 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
1237 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
1238 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
1239 error = true;
1241 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1242 tr("Your configuration is invalid. Please go to the configuration "
1243 "dialog and make sure the selected values are correct."));
1245 return error;
1248 void RbUtilQt::checkUpdate(void)
1250 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1251 #if defined(Q_OS_WIN32)
1252 url += "win32/";
1253 #elif defined(Q_OS_LINUX)
1254 url += "linux/";
1255 #elif defined(Q_OS_MACX)
1256 url += "macosx/";
1257 #endif
1259 update = new HttpGet(this);
1260 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
1261 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
1262 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1263 update->setCache(true);
1265 update->getFile(QUrl(url));
1268 void RbUtilQt::downloadUpdateDone(bool error)
1270 if(error) {
1271 qDebug() << "[RbUtil] network error:" << update->error();
1273 else {
1274 QString toParse(update->readAll());
1276 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
1277 QStringList rbutilList;
1278 int pos = 0;
1279 while ((pos = searchString.indexIn(toParse, pos)) != -1)
1281 rbutilList << searchString.cap(1);
1282 pos += searchString.matchedLength();
1284 qDebug() << "[Checkupdate] " << rbutilList;
1286 QString newVersion ="";
1287 //check if there is a binary with higher version in this list
1288 for(int i=0; i < rbutilList.size(); i++)
1290 #if defined(Q_OS_LINUX)
1291 #if defined(__amd64__)
1292 //skip if it isnt a 64bit build
1293 if( !rbutilList.at(i).contains("64bit"))
1294 continue;
1295 #else
1296 //skip if it is a 64bit build
1297 if(rbutilList.at(i).contains("64bit"))
1298 continue;
1299 #endif
1300 #endif
1301 //check if it is newer, and remember newest
1302 if(newerVersion(VERSION,rbutilList.at(i)))
1304 if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i)))
1306 newVersion = rbutilList.at(i);
1311 // if we found something newer, display info
1312 if(newVersion != "")
1314 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1315 #if defined(Q_OS_WIN32)
1316 url += "win32/";
1317 #elif defined(Q_OS_LINUX)
1318 url += "linux/";
1319 #elif defined(Q_OS_MACX)
1320 url += "macosx/";
1321 #endif
1322 url += newVersion;
1324 QMessageBox::information(this,tr("RockboxUtility Update available"),
1325 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1326 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
1331 bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
1333 QRegExp chars("\\d*(\\D)");
1335 //strip non-number from beginning
1336 versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
1337 versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
1339 // split versions by "."
1340 QStringList versionListOld = versionOld.split(".");
1341 QStringList versionListNew = versionNew.split(".");
1343 QStringListIterator iteratorOld(versionListOld);
1344 QStringListIterator iteratorNew(versionListNew);
1346 //check every section
1347 while(iteratorOld.hasNext() && iteratorNew.hasNext())
1349 QString newPart = iteratorNew.next();
1350 QString oldPart = iteratorOld.next();
1351 QString newPartChar = "", oldPartChar = "";
1352 int newPartInt = 0, oldPartInt =0;
1354 //convert to int, if it contains chars, put into seperated variable
1355 if(newPart.contains(chars))
1357 newPartChar = chars.cap(1);
1358 newPart = newPart.remove(newPartChar);
1360 newPartInt = newPart.toInt();
1361 //convert to int, if it contains chars, put into seperated variable
1362 if(oldPart.contains(chars))
1364 oldPartChar = chars.cap(1);
1365 oldPart = oldPart.remove(oldPartChar);
1367 oldPartInt = oldPart.toInt();
1369 if(newPartInt > oldPartInt) // this section int is higher -> true
1370 return true;
1371 else if(newPartInt < oldPartInt) //this section int is lower -> false
1372 return false;
1373 else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
1374 return true;
1375 else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
1376 return false;
1377 //all the same, next section
1379 // all the same -> false
1380 return false;