Sort rbutil.ini general section and rename voice_url for clarity.
[kugel-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blobd503da00e4bbbd43872f117ff8e7960a9c7fccae
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 "bootloaderinstallmpio.h"
48 #if defined(Q_OS_LINUX)
49 #include <stdio.h>
50 #endif
51 #if defined(Q_OS_WIN32)
52 #if defined(UNICODE)
53 #define _UNICODE
54 #endif
55 #include <stdio.h>
56 #include <tchar.h>
57 #include <windows.h>
58 #endif
60 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
62 // startup log
63 qDebug() << "======================================";
64 qDebug() << "[System] Rockbox Utility " VERSION;
65 qDebug() << "[System] Qt version:" << qVersion();
66 qDebug() << "======================================";
68 absolutePath = qApp->applicationDirPath();
70 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
71 HttpGet::setGlobalProxy(proxy());
72 // init startup & autodetection
73 ui.setupUi(this);
74 #if defined(Q_OS_LINUX)
75 QIcon windowIcon(":/icons/rockbox-clef.svg");
76 this->setWindowIcon(windowIcon);
77 #endif
79 #if defined(Q_OS_WIN32)
80 long ret;
81 HKEY hk;
82 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Wine"),
83 0, KEY_QUERY_VALUE, &hk);
84 if(ret == ERROR_SUCCESS) {
85 QMessageBox::warning(this, tr("Wine detected!"),
86 tr("It seems you are trying to run this program under Wine. "
87 "Please don't do this, running under Wine will fail. "
88 "Use the native Linux binary instead."),
89 QMessageBox::Ok, QMessageBox::Ok);
90 qDebug() << "[RbUtil] WINE DETECTED!";
91 RegCloseKey(hk);
93 #endif
94 downloadInfo();
96 m_gotInfo = false;
97 m_auto = false;
99 // manual tab
100 ui.radioPdf->setChecked(true);
102 // info tab
103 ui.treeInfo->setAlternatingRowColors(true);
104 ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version"));
105 ui.treeInfo->expandAll();
106 ui.treeInfo->setColumnCount(2);
107 ui.treeInfo->setLayoutDirection(Qt::LeftToRight);
108 // disable quick install until version info is available
109 ui.buttonSmall->setEnabled(false);
110 ui.buttonComplete->setEnabled(false);
111 ui.actionSmall_Installation->setEnabled(false);
112 ui.actionComplete_Installation->setEnabled(false);
114 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
115 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
116 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
117 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
118 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
119 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
120 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
121 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(installBtn()));
122 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBootloaderBtn()));
123 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFontsBtn()));
124 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoomBtn()));
125 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
126 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
127 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
128 connect(ui.buttonThemes, SIGNAL(clicked()), this, SLOT(installThemes()));
129 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
130 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
131 connect(ui.buttonDownloadManual, SIGNAL(clicked()), this, SLOT(downloadManual()));
132 connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall()));
133 connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall()));
135 // actions accessible from the menu
136 connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall()));
137 connect(ui.actionSmall_Installation, SIGNAL(triggered()), this, SLOT(smallInstall()));
138 connect(ui.actionInstall_Bootloader, SIGNAL(triggered()), this, SLOT(installBootloaderBtn()));
139 connect(ui.actionInstall_Rockbox, SIGNAL(triggered()), this, SLOT(installBtn()));
140 connect(ui.actionFonts_Package, SIGNAL(triggered()), this, SLOT(installFontsBtn()));
141 connect(ui.actionInstall_Themes, SIGNAL(triggered()), this, SLOT(installThemes()));
142 connect(ui.actionInstall_Game_Files, SIGNAL(triggered()), this, SLOT(installDoomBtn()));
143 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
144 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
145 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
146 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
147 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
148 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
149 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
151 #if !defined(STATIC)
152 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
153 #else
154 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
155 #endif
160 void RbUtilQt::shutdown(void)
162 // restore default message handler to prevent trace accesses during
163 // object destruction -- the trace object could already be destroyed.
164 // Fixes segfaults on exit.
165 qInstallMsgHandler(0);
166 SysTrace::save();
167 this->close();
171 void RbUtilQt::trace(void)
173 SysTrace wnd(this);
174 wnd.exec();
177 void RbUtilQt::sysinfo(void)
179 Sysinfo info(this);
180 info.exec();
183 void RbUtilQt::updateTabs(int count)
185 switch(count) {
186 case 6:
187 updateInfo();
188 break;
189 default:
190 break;
195 void RbUtilQt::downloadInfo()
197 // try to get the current build information
198 daily = new HttpGet(this);
199 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
200 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
201 if(RbSettings::value(RbSettings::CacheOffline).toBool())
202 daily->setCache(true);
203 else
204 daily->setCache(false);
205 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
206 qDebug() << "[RbUtil] downloading build info";
207 daily->setFile(&buildInfo);
208 daily->getFile(QUrl(SystemInfo::value(SystemInfo::ServerConfUrl).toString()));
212 void RbUtilQt::downloadDone(bool error)
214 if(error) {
215 qDebug() << "[RbUtil] network error:" << daily->error();
216 ui.statusbar->showMessage(tr("Can't get version information!"));
217 QMessageBox::critical(this, tr("Network error"),
218 tr("Can't get version information.\n"
219 "Network error: %1. Please check your network and proxy settings.")
220 .arg(daily->errorString()));
221 return;
223 qDebug() << "[RbUtil] network status:" << daily->error();
225 // read info into ServerInfo object
226 buildInfo.open();
227 ServerInfo::readBuildInfo(buildInfo.fileName());
228 buildInfo.close();
230 // start bleeding info download
231 bleeding = new HttpGet(this);
232 connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool)));
233 connect(qApp, SIGNAL(lastWindowClosed()), bleeding, SLOT(abort()));
234 if(RbSettings::value(RbSettings::CacheOffline).toBool())
235 bleeding->setCache(true);
236 bleeding->setFile(&bleedingInfo);
237 bleeding->getFile(QUrl(SystemInfo::value(SystemInfo::BleedingInfo).toString()));
238 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
243 void RbUtilQt::downloadBleedingDone(bool error)
245 if(error) {
246 qDebug() << "[RbUtil] network error:" << bleeding->error();
247 ui.statusbar->showMessage(tr("Can't get version information!"));
248 QMessageBox::critical(this, tr("Network error"),
249 tr("Can't get version information.\n"
250 "Network error: %1. Please check your network and proxy settings.")
251 .arg(bleeding->errorString()));
252 return;
254 else {
255 bleedingInfo.open();
256 ServerInfo::readBleedingInfo(bleedingInfo.fileName());
257 bleedingInfo.close();
259 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
260 updateSettings();
261 m_gotInfo = true;
263 //start check for updates
264 checkUpdate();
269 void RbUtilQt::about()
271 QDialog *window = new QDialog(this);
272 Ui::aboutBox about;
273 about.setupUi(window);
274 window->setLayoutDirection(Qt::LeftToRight);
275 window->setModal(true);
277 QFile licence(":/docs/gpl-2.0.html");
278 licence.open(QIODevice::ReadOnly);
279 QTextStream c(&licence);
280 QString cline = c.readAll();
281 about.browserLicense->insertHtml(cline);
282 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
283 QFile credits(":/docs/CREDITS");
284 credits.open(QIODevice::ReadOnly);
285 QTextStream r(&credits);
286 r.setCodec(QTextCodec::codecForName("UTF-8"));
287 while(!r.atEnd()) {
288 QString line = r.readLine();
289 // filter out header.
290 line.remove(QRegExp("^[^A-Z]+.*"));
291 line.remove(QRegExp("^People.*"));
292 about.browserCredits->append(line);
294 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
295 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
296 about.labelTitle->setText(title);
298 window->show();
303 void RbUtilQt::help()
305 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
306 QDesktopServices::openUrl(helpurl);
310 void RbUtilQt::configDialog()
312 Config *cw = new Config(this);
313 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
314 cw->show();
318 void RbUtilQt::updateSettings()
320 qDebug() << "[RbUtil] updating current settings";
321 updateDevice();
322 updateManual();
323 HttpGet::setGlobalProxy(proxy());
324 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
325 HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
327 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
328 QApplication::processEvents();
329 QMessageBox::information(this, tr("New installation"),
330 tr("This is a new installation of Rockbox Utility, or a new version. "
331 "The configuration dialog will now open to allow you to setup the program, "
332 " or review your settings."));
333 configDialog();
335 else if(chkConfig(false)) {
336 QApplication::processEvents();
337 QMessageBox::critical(this, tr("Configuration error"),
338 tr("Your configuration is invalid. This is most likely due "
339 "to a changed device path. The configuration dialog will "
340 "now open to allow you to correct the problem."));
341 configDialog();
346 void RbUtilQt::updateDevice()
348 /* TODO: We should check the flags of the bootloaderinstall classes, and not
349 * just check if its != none or != "fwpatcher" */
351 /* Enable bootloader installation, if possible */
352 bool bootloaderInstallable =
353 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
354 ui.buttonBootloader->setEnabled(bootloaderInstallable);
355 ui.labelBootloader->setEnabled(bootloaderInstallable);
356 ui.actionInstall_Bootloader->setEnabled(bootloaderInstallable);
358 /* Enable bootloader uninstallation, if possible */
359 bool bootloaderUninstallable = bootloaderInstallable &&
360 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
361 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
362 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
363 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
365 /* Disable the whole tab widget if configuration is invalid */
366 bool configurationValid = !chkConfig(false);
367 ui.tabWidget->setEnabled(configurationValid);
368 ui.menuA_ctions->setEnabled(configurationValid);
370 // displayed device info
371 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
372 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
373 QString name = SystemInfo::value(SystemInfo::CurName).toString() +
374 " (" + ServerInfo::value(ServerInfo::CurStatus).toString() + ")";
375 if(name.isEmpty()) name = "&lt;none&gt;";
376 if(mountpoint.isEmpty()) mountpoint = "&lt;invalid&gt;";
377 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
378 .arg(brand, name, QDir::toNativeSeparators(mountpoint)));
380 // hide quickstart buttons if no release available
381 bool installable = !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty();
382 ui.buttonSmall->setEnabled(installable);
383 ui.buttonComplete->setEnabled(installable);
384 ui.actionSmall_Installation->setEnabled(installable);
385 ui.actionComplete_Installation->setEnabled(installable);
389 void RbUtilQt::updateManual()
391 if(RbSettings::value(RbSettings::Platform) != "")
393 QString manual= SystemInfo::value(SystemInfo::CurManual).toString();
395 if(manual == "")
396 manual = "rockbox-"
397 + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
398 QString pdfmanual;
399 pdfmanual = SystemInfo::value(SystemInfo::ManualUrl).toString()
400 + "/" + manual + ".pdf";
401 QString htmlmanual;
402 htmlmanual = SystemInfo::value(SystemInfo::ManualUrl).toString()
403 + "/" + manual + "/rockbox-build.html";
404 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
405 .arg(pdfmanual));
406 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
407 .arg(htmlmanual));
409 else {
410 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
411 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
412 .arg("http://www.rockbox.org/manual.shtml"));
417 void RbUtilQt::completeInstall()
419 if(chkConfig(true)) return;
420 if(QMessageBox::question(this, tr("Confirm Installation"),
421 tr("Do you really want to perform a complete installation?\n\n"
422 "This will install Rockbox %1. To install the most recent "
423 "development build available press \"Cancel\" and "
424 "use the \"Installation\" tab.")
425 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
426 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
427 return;
428 // create logger
429 logger = new ProgressLoggerGui(this);
430 logger->show();
432 if(smallInstallInner())
433 return;
434 logger->setRunning();
435 // Fonts
436 m_error = false;
437 m_installed = false;
438 if(!installFontsAuto())
439 return;
440 else
442 // wait for installation finished
443 while(!m_installed)
444 QApplication::processEvents();
446 if(m_error) return;
447 logger->setRunning();
449 // Doom
450 if(hasDoom())
452 m_error = false;
453 m_installed = false;
454 if(!installDoomAuto())
455 return;
456 else
458 // wait for installation finished
459 while(!m_installed)
460 QApplication::processEvents();
462 if(m_error) return;
465 // theme
466 // this is a window
467 // it has its own logger window,so close our.
468 logger->close();
469 installThemes();
473 void RbUtilQt::smallInstall()
475 if(chkConfig(true)) return;
476 if(QMessageBox::question(this, tr("Confirm Installation"),
477 tr("Do you really want to perform a minimal installation? "
478 "A minimal installation will contain only the absolutely "
479 "necessary parts to run Rockbox.\n\n"
480 "This will install Rockbox %1. To install the most recent "
481 "development build available press \"Cancel\" and "
482 "use the \"Installation\" tab.")
483 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()),
484 QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
485 return;
487 // create logger
488 logger = new ProgressLoggerGui(this);
489 logger->show();
491 smallInstallInner();
494 bool RbUtilQt::smallInstallInner()
496 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
497 // show dialog with error if mount point is wrong
498 if(!QFileInfo(mountpoint).isDir()) {
499 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
500 logger->setFinished();
501 return true;
503 // Bootloader
504 if(SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none")
506 m_error = false;
507 m_installed = false;
508 m_auto = true;
509 if(!installBootloaderAuto()) {
510 logger->setFinished();
511 return true;
513 else
515 // wait for boot loader installation finished
516 while(!m_installed)
517 QApplication::processEvents();
519 m_auto = false;
520 if(m_error) return true;
521 logger->setRunning();
524 // Rockbox
525 m_error = false;
526 m_installed = false;
527 if(!installAuto())
528 return true;
529 else
531 // wait for installation finished
532 while(!m_installed)
533 QApplication::processEvents();
536 installBootloaderPost(false);
537 return false;
540 void RbUtilQt::installdone(bool error)
542 qDebug() << "[RbUtil] install done";
543 m_installed = true;
544 m_error = error;
547 void RbUtilQt::installBtn()
549 if(chkConfig(true)) return;
550 install();
553 bool RbUtilQt::installAuto()
555 QString file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
556 file.replace("%MODEL%", SystemInfo::value(SystemInfo::CurBuildserverModel).toString());
557 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
559 // check installed Version and Target
560 QString warning = Utils::checkEnvironment(false);
561 if(!warning.isEmpty())
563 if(QMessageBox::warning(this, tr("Really continue?"), warning,
564 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
565 == QMessageBox::Abort)
567 logger->addItem(tr("Aborted!"), LOGERROR);
568 logger->setFinished();
569 return false;
573 // check version
574 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
575 if(rbinfo.version() != "")
577 if(QMessageBox::question(this, tr("Installed Rockbox detected"),
578 tr("Rockbox installation detected. Do you want to backup first?"),
579 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
581 logger->addItem(tr("Starting backup..."),LOGINFO);
582 QString backupName = RbSettings::value(RbSettings::Mountpoint).toString()
583 + "/.backup/rockbox-backup-" + rbinfo.version() + ".zip";
585 //! create dir, if it doesnt exist
586 QFileInfo backupFile(backupName);
587 if(!QDir(backupFile.path()).exists())
589 QDir a;
590 a.mkpath(backupFile.path());
593 //! create backup
594 RbZip backup;
595 connect(&backup,SIGNAL(zipProgress(int,int)),logger, SLOT(setProgress(int,int)));
596 if(backup.createZip(backupName,
597 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
599 logger->addItem(tr("Backup successful"),LOGOK);
601 else
603 logger->addItem(tr("Backup failed!"),LOGERROR);
604 logger->setFinished();
605 return false;
610 //! install current build
611 ZipInstaller* installer = new ZipInstaller(this);
612 installer->setUrl(file);
613 installer->setLogSection("Rockbox (Base)");
614 installer->setLogVersion(ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
615 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
616 installer->setCache(true);
617 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
619 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
620 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
621 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
622 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
623 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
624 installer->install();
625 return true;
629 void RbUtilQt::install()
631 InstallWindow *installWindow = new InstallWindow(this);
632 installWindow->show();
635 bool RbUtilQt::installBootloaderAuto()
637 installBootloader();
638 return !m_error;
641 void RbUtilQt::installBootloaderBtn()
643 if(chkConfig(true)) return;
644 if(QMessageBox::question(this, tr("Confirm Installation"),
645 tr("Do you really want to install the Bootloader?"),
646 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
648 // create logger
649 logger = new ProgressLoggerGui(this);
650 logger->show();
651 installBootloader();
654 void RbUtilQt::installBootloader()
656 QString platform = RbSettings::value(RbSettings::Platform).toString();
657 QString backupDestination = "";
658 m_error = false;
660 // create installer
661 BootloaderInstallBase *bl = BootloaderInstallBase::createBootloaderInstaller(this,
662 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
663 if(bl == NULL) {
664 logger->addItem(tr("No install method known."), LOGERROR);
665 logger->setFinished();
666 return;
669 // set bootloader filename. Do this now as installed() needs it.
670 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
671 QStringList blfilepath;
672 for(int a = 0; a < blfile.size(); a++) {
673 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
674 + blfile.at(a));
676 bl->setBlFile(blfilepath);
677 QUrl url(SystemInfo::value(SystemInfo::BootloaderUrl).toString()
678 + SystemInfo::value(SystemInfo::CurBootloaderName).toString());
679 bl->setBlUrl(url);
680 bl->setLogfile(RbSettings::value(RbSettings::Mountpoint).toString()
681 + "/.rockbox/rbutil.log");
683 if(bl->installed() == BootloaderInstallBase::BootloaderRockbox) {
684 if(QMessageBox::question(this, tr("Bootloader detected"),
685 tr("Bootloader already installed. Do you want to reinstall the bootloader?"),
686 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
687 if(m_auto) {
688 // keep logger open for auto installs.
689 // don't consider abort as error in auto-mode.
690 logger->addItem(tr("Bootloader installation skipped"), LOGINFO);
691 installBootloaderPost(false);
693 else {
694 logger->close();
695 installBootloaderPost(true);
697 delete bl;
698 return;
701 else if(bl->installed() == BootloaderInstallBase::BootloaderOther
702 && bl->capabilities() & BootloaderInstallBase::Backup)
704 QString targetFolder = SystemInfo::value(SystemInfo::CurPlatformName).toString()
705 + " Firmware Backup";
706 // remove invalid character(s)
707 targetFolder.remove(QRegExp("[:/]"));
708 if(QMessageBox::question(this, tr("Create Bootloader backup"),
709 tr("You can create a backup of the original bootloader "
710 "file. Press \"Yes\" to select an output folder on your "
711 "computer to save the file to. The file will get placed "
712 "in a new folder \"%1\" created below the selected folder.\n"
713 "Press \"No\" to skip this step.").arg(targetFolder),
714 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
715 backupDestination = QFileDialog::getExistingDirectory(this,
716 tr("Browse backup folder"), QDir::homePath());
717 if(!backupDestination.isEmpty())
718 backupDestination += "/" + targetFolder;
720 qDebug() << "[RbUtil] backing up to" << backupDestination;
721 // backup needs to be done after the logger has been set up.
725 if(bl->capabilities() & BootloaderInstallBase::NeedsOf)
727 int ret;
728 ret = QMessageBox::information(this, tr("Prerequisites"),
729 bl->ofHint(),QMessageBox::Ok | QMessageBox::Abort);
730 if(ret != QMessageBox::Ok) {
731 // consider aborting an error to close window / abort automatic
732 // installation.
733 m_error = true;
734 logger->addItem(tr("Bootloader installation aborted"), LOGINFO);
735 logger->setFinished();
736 return;
738 // open dialog to browse to of file
739 QString offile;
740 offile = QFileDialog::getOpenFileName(this,
741 tr("Select firmware file"), QDir::homePath());
742 if(!QFileInfo(offile).isReadable()) {
743 logger->addItem(tr("Error opening firmware file"), LOGERROR);
744 logger->setFinished();
745 m_error = true;
746 return;
748 bl->setOfFile(offile);
751 // the bootloader install class does NOT use any GUI stuff.
752 // All messages are passed via signals.
753 connect(bl, SIGNAL(done(bool)), logger, SLOT(setFinished()));
754 connect(bl, SIGNAL(done(bool)), this, SLOT(installBootloaderPost(bool)));
755 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
756 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
758 // start install.
759 if(!backupDestination.isEmpty()) {
760 if(!bl->backup(backupDestination)) {
761 if(QMessageBox::warning(this, tr("Backup error"),
762 tr("Could not create backup file. Continue?"),
763 QMessageBox::No | QMessageBox::Yes)
764 == QMessageBox::No) {
765 logger->setFinished();
766 return;
770 bl->install();
773 void RbUtilQt::installBootloaderPost(bool error)
775 qDebug() << "[RbUtil] Bootloader Post-Installation, error state:" << error;
776 // if an error occured don't perform post install steps.
777 if(error) {
778 m_error = true;
779 return;
781 else
782 m_error = false;
784 m_installed = true;
785 // end here if automated install
786 if(m_auto)
787 return;
789 QString msg = BootloaderInstallBase::postinstallHints(
790 RbSettings::value(RbSettings::Platform).toString());
791 if(!msg.isEmpty()) {
792 QMessageBox::information(this, tr("Manual steps required"), msg);
793 logger->close();
798 void RbUtilQt::installFontsBtn()
800 if(chkConfig(true)) return;
801 if(QMessageBox::question(this, tr("Confirm Installation"),
802 tr("Do you really want to install the fonts package?"),
803 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
804 // create logger
805 logger = new ProgressLoggerGui(this);
806 logger->show();
807 installFonts();
810 bool RbUtilQt::installFontsAuto()
812 installFonts();
814 return !m_error;
817 void RbUtilQt::installFonts()
819 // create zip installer
820 installer = new ZipInstaller(this);
822 installer->setUrl(SystemInfo::value(SystemInfo::FontUrl).toString());
823 installer->setLogSection("Fonts");
824 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
825 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
826 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
827 installer->setCache(true);
829 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
830 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
831 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
832 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
833 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
834 installer->install();
838 void RbUtilQt::installVoice()
840 if(chkConfig(true)) return;
842 if(m_gotInfo == false)
844 QMessageBox::warning(this, tr("Warning"),
845 tr("The Application is still downloading Information about new Builds."
846 " Please try again shortly."));
847 return;
850 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
851 RockboxInfo installInfo(mountpoint);
853 QString voiceurl;
854 QString logversion;
855 QString relversion = installInfo.release();
856 // if no version is found abort.
857 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
858 QMessageBox::critical(this, tr("No Rockbox installation found"),
859 tr("Could not determine the installed Rockbox version. "
860 "Please install a Rockbox build before installing "
861 "voice files."));
862 return;
864 if(relversion.isEmpty()) {
865 // release is empty for non-release versions (i.e. daily / current)
866 voiceurl = SystemInfo::value(SystemInfo::DailyVoiceUrl).toString();
867 logversion = installInfo.revision();
869 else {
870 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
871 logversion = installInfo.release();
873 if(QMessageBox::question(this, tr("Confirm Installation"),
874 tr("Do you really want to install the voice file?"),
875 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
876 return;
878 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
879 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
880 // replace placeholder in voice url
881 voiceurl.replace("%DATE%", date.toString("yyyyMMdd"));
882 voiceurl.replace("%MODEL%", model);
883 voiceurl.replace("%RELVERSION%", relversion);
885 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
887 // create logger
888 logger = new ProgressLoggerGui(this);
889 logger->show();
890 // create zip installer
891 installer = new ZipInstaller(this);
893 installer->setUrl(voiceurl);
894 installer->setLogSection("Voice");
895 installer->setLogVersion(logversion);
896 installer->setMountPoint(mountpoint);
897 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
898 installer->setCache(true);
899 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
900 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
901 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
902 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
903 installer->install();
907 void RbUtilQt::installDoomBtn()
909 if(chkConfig(true)) return;
910 if(!hasDoom()){
911 QMessageBox::critical(this, tr("Error"),
912 tr("Your device doesn't have a doom plugin. Aborting."));
913 return;
916 if(QMessageBox::question(this, tr("Confirm Installation"),
917 tr("Do you really want to install the game addon files?"),
918 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
919 // create logger
920 logger = new ProgressLoggerGui(this);
921 logger->show();
923 installDoom();
925 bool RbUtilQt::installDoomAuto()
927 installDoom();
928 return !m_error;
931 bool RbUtilQt::hasDoom()
933 QFile doomrock(RbSettings::value(RbSettings::Mountpoint).toString()
934 +"/.rockbox/rocks/games/doom.rock");
935 return doomrock.exists();
938 void RbUtilQt::installDoom()
940 // create zip installer
941 installer = new ZipInstaller(this);
943 installer->setUrl(SystemInfo::value(SystemInfo::DoomUrl).toString());
944 installer->setLogSection("Game Addons");
945 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
946 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
947 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
948 installer->setCache(true);
949 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
950 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
951 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
952 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
953 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
954 installer->install();
958 void RbUtilQt::installThemes()
960 if(chkConfig(true)) return;
961 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
962 tw->setModal(true);
963 tw->show();
966 void RbUtilQt::createTalkFiles(void)
968 if(chkConfig(true)) return;
969 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
970 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
971 installWindow->show();
975 void RbUtilQt::createVoiceFile(void)
977 if(chkConfig(true)) return;
978 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
980 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
981 installWindow->show();
984 void RbUtilQt::uninstall(void)
986 if(chkConfig(true)) return;
987 UninstallWindow *uninstallWindow = new UninstallWindow(this);
988 uninstallWindow->show();
992 void RbUtilQt::uninstallBootloader(void)
994 if(chkConfig(true)) return;
995 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
996 tr("Do you really want to uninstall the Bootloader?"),
997 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
998 // create logger
999 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1000 logger->setProgressVisible(false);
1001 logger->show();
1003 QString platform = RbSettings::value(RbSettings::Platform).toString();
1005 // create installer
1006 BootloaderInstallBase *bl = BootloaderInstallBase::createBootloaderInstaller(this,
1007 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
1009 if(bl == NULL ) {
1010 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
1011 logger->setFinished();
1012 return;
1014 if( (bl->capabilities() & BootloaderInstallBase::Uninstall) == 0)
1016 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target."
1017 "Try a normal firmware update to remove the booloader."), LOGERROR);
1018 logger->setFinished();
1019 delete bl;
1020 return;
1023 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
1024 QStringList blfilepath;
1025 for(int a = 0; a < blfile.size(); a++) {
1026 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
1027 + blfile.at(a));
1029 bl->setBlFile(blfilepath);
1031 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1032 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1034 int result;
1035 result = bl->uninstall();
1037 logger->setFinished();
1042 void RbUtilQt::downloadManual(void)
1044 if(chkConfig(true)) return;
1045 if(QMessageBox::question(this, tr("Confirm download"),
1046 tr("Do you really want to download the manual? The manual will be saved "
1047 "to the root folder of your player."),
1048 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1049 return;
1051 QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
1052 if(manual.isEmpty())
1053 manual = "rockbox-"
1054 + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
1056 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
1058 QString manualurl;
1059 QString target;
1060 QString section;
1061 if(ui.radioPdf->isChecked()) {
1062 target = "/" + manual + ".pdf";
1063 section = "Manual (PDF)";
1065 else {
1066 target = "/" + manual + "-" + date.toString("yyyyMMdd") + "-html.zip";
1067 section = "Manual (HTML)";
1069 manualurl = SystemInfo::value(SystemInfo::ManualUrl).toString() + "/" + target;
1070 qDebug() << "[RbUtil] Manual URL:" << manualurl;
1072 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1073 logger->show();
1074 installer = new ZipInstaller(this);
1075 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
1076 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
1077 installer->setCache(true);
1078 installer->setLogSection(section);
1079 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
1080 installer->setUrl(manualurl);
1081 installer->setUnzip(false);
1082 installer->setTarget(target);
1083 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1084 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1085 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
1086 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
1087 installer->install();
1091 void RbUtilQt::installPortable(void)
1093 if(QMessageBox::question(this, tr("Confirm installation"),
1094 tr("Do you really want to install Rockbox Utility to your player? "
1095 "After installation you can run it from the players hard drive."),
1096 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1097 return;
1099 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1100 logger->setProgressMax(0);
1101 logger->setProgressValue(0);
1102 logger->show();
1103 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
1105 // check mountpoint
1106 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
1107 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
1108 logger->setFinished();
1109 return;
1112 // remove old files first.
1113 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1114 + "/RockboxUtility.exe");
1115 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1116 + "/RockboxUtility.ini");
1117 // copy currently running binary and currently used settings file
1118 if(!QFile::copy(qApp->applicationFilePath(),
1119 RbSettings::value(RbSettings::Mountpoint).toString()
1120 + "/RockboxUtility.exe")) {
1121 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
1122 logger->setFinished();
1123 return;
1125 logger->addItem(tr("Installing user configuration"), LOGINFO);
1126 if(!QFile::copy(RbSettings::userSettingFilename(),
1127 RbSettings::value(RbSettings::Mountpoint).toString()
1128 + "/RockboxUtility.ini")) {
1129 logger->addItem(tr("Error installing user configuration"), LOGERROR);
1130 logger->setFinished();
1131 return;
1133 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
1134 logger->setFinished();
1135 logger->setProgressMax(1);
1136 logger->setProgressValue(1);
1141 void RbUtilQt::updateInfo()
1143 qDebug() << "[RbUtil] updating server info";
1145 QString mp = RbSettings::value(RbSettings::Mountpoint).toString();
1146 QSettings log(mp + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
1147 QStringList groups = log.childGroups();
1148 QList<QTreeWidgetItem *> items;
1149 QTreeWidgetItem *w, *w2;
1150 QString min, max;
1151 int olditems = 0;
1153 // remove old list entries (if any)
1154 int l = ui.treeInfo->topLevelItemCount();
1155 while(l--) {
1156 QTreeWidgetItem *m;
1157 m = ui.treeInfo->takeTopLevelItem(l);
1158 // delete childs (single level deep, no recursion here)
1159 int n = m->childCount();
1160 while(n--)
1161 delete m->child(n);
1163 // get and populate new items
1164 for(int a = 0; a < groups.size(); a++) {
1165 log.beginGroup(groups.at(a));
1166 QStringList keys = log.allKeys();
1167 w = new QTreeWidgetItem;
1168 w->setFlags(Qt::ItemIsEnabled);
1169 w->setText(0, groups.at(a));
1170 items.append(w);
1171 // get minimum and maximum version information so we can hilight old files
1172 min = max = log.value(keys.at(0)).toString();
1173 for(int b = 0; b < keys.size(); b++) {
1174 if(log.value(keys.at(b)).toString() > max)
1175 max = log.value(keys.at(b)).toString();
1176 if(log.value(keys.at(b)).toString() < min)
1177 min = log.value(keys.at(b)).toString();
1180 for(int b = 0; b < keys.size(); b++) {
1181 QString file;
1182 file = mp + "/" + keys.at(b);
1183 if(QFileInfo(file).isDir())
1184 continue;
1185 w2 = new QTreeWidgetItem(w, QStringList() << "/"
1186 + keys.at(b) << log.value(keys.at(b)).toString());
1187 if(log.value(keys.at(b)).toString() != max) {
1188 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
1189 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
1190 olditems++;
1192 items.append(w2);
1194 log.endGroup();
1195 if(min != max)
1196 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
1197 else
1198 w->setData(1, Qt::DisplayRole, max);
1200 ui.treeInfo->insertTopLevelItems(0, items);
1201 ui.treeInfo->resizeColumnToContents(0);
1205 QUrl RbUtilQt::proxy()
1207 if(RbSettings::value(RbSettings::ProxyType) == "manual")
1208 return QUrl(RbSettings::value(RbSettings::Proxy).toString());
1209 else if(RbSettings::value(RbSettings::ProxyType) == "system")
1210 return System::systemProxy();
1211 return QUrl("");
1215 bool RbUtilQt::chkConfig(bool warn)
1217 bool error = false;
1218 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
1219 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
1220 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
1221 error = true;
1223 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1224 tr("Your configuration is invalid. Please go to the configuration "
1225 "dialog and make sure the selected values are correct."));
1227 return error;
1230 void RbUtilQt::checkUpdate(void)
1232 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1233 #if defined(Q_OS_WIN32)
1234 url += "win32/";
1235 #elif defined(Q_OS_LINUX)
1236 url += "linux/";
1237 #elif defined(Q_OS_MACX)
1238 url += "macosx/";
1239 #endif
1241 update = new HttpGet(this);
1242 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
1243 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
1244 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1245 update->setCache(true);
1247 update->getFile(QUrl(url));
1250 void RbUtilQt::downloadUpdateDone(bool error)
1252 if(error) {
1253 qDebug() << "[RbUtil] network error:" << update->error();
1255 else {
1256 QString toParse(update->readAll());
1258 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
1259 QStringList rbutilList;
1260 int pos = 0;
1261 while ((pos = searchString.indexIn(toParse, pos)) != -1)
1263 rbutilList << searchString.cap(1);
1264 pos += searchString.matchedLength();
1266 qDebug() << "[Checkupdate] " << rbutilList;
1268 QString newVersion ="";
1269 //check if there is a binary with higher version in this list
1270 for(int i=0; i < rbutilList.size(); i++)
1272 #if defined(Q_OS_LINUX)
1273 #if defined(__amd64__)
1274 //skip if it isnt a 64bit build
1275 if( !rbutilList.at(i).contains("64bit"))
1276 continue;
1277 #else
1278 //skip if it is a 64bit build
1279 if(rbutilList.at(i).contains("64bit"))
1280 continue;
1281 #endif
1282 #endif
1283 //check if it is newer, and remember newest
1284 if(newerVersion(VERSION,rbutilList.at(i)))
1286 if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i)))
1288 newVersion = rbutilList.at(i);
1293 // if we found something newer, display info
1294 if(newVersion != "")
1296 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1297 #if defined(Q_OS_WIN32)
1298 url += "win32/";
1299 #elif defined(Q_OS_LINUX)
1300 url += "linux/";
1301 #elif defined(Q_OS_MACX)
1302 url += "macosx/";
1303 #endif
1304 url += newVersion;
1306 QMessageBox::information(this,tr("RockboxUtility Update available"),
1307 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1308 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
1313 bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
1315 QRegExp chars("\\d*(\\D)");
1317 //strip non-number from beginning
1318 versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
1319 versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
1321 // split versions by "."
1322 QStringList versionListOld = versionOld.split(".");
1323 QStringList versionListNew = versionNew.split(".");
1325 QStringListIterator iteratorOld(versionListOld);
1326 QStringListIterator iteratorNew(versionListNew);
1328 //check every section
1329 while(iteratorOld.hasNext() && iteratorNew.hasNext())
1331 QString newPart = iteratorNew.next();
1332 QString oldPart = iteratorOld.next();
1333 QString newPartChar = "", oldPartChar = "";
1334 int newPartInt = 0, oldPartInt =0;
1336 //convert to int, if it contains chars, put into seperated variable
1337 if(newPart.contains(chars))
1339 newPartChar = chars.cap(1);
1340 newPart = newPart.remove(newPartChar);
1342 newPartInt = newPart.toInt();
1343 //convert to int, if it contains chars, put into seperated variable
1344 if(oldPart.contains(chars))
1346 oldPartChar = chars.cap(1);
1347 oldPart = oldPart.remove(oldPartChar);
1349 oldPartInt = oldPart.toInt();
1351 if(newPartInt > oldPartInt) // this section int is higher -> true
1352 return true;
1353 else if(newPartInt < oldPartInt) //this section int is lower -> false
1354 return false;
1355 else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
1356 return true;
1357 else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
1358 return false;
1359 //all the same, next section
1361 // all the same -> false
1362 return false;