Theme Editor: Began implementing classes to display project files and settings in...
[kugel-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blob4485bacaec6b61fdc975ee24ad27341a3c6c325e
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 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
802 RockboxInfo installInfo(mountpoint);
803 if(installInfo.revision().isEmpty() && installInfo.release().isEmpty()) {
804 QMessageBox::critical(this, tr("No Rockbox installation found"),
805 tr("Could not determine the installed Rockbox version. "
806 "Please install a Rockbox build before installing "
807 "fonts."));
808 return;
810 if(QMessageBox::question(this, tr("Confirm Installation"),
811 tr("Do you really want to install the fonts package?"),
812 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
813 // create logger
814 logger = new ProgressLoggerGui(this);
815 logger->show();
816 installFonts();
819 bool RbUtilQt::installFontsAuto()
821 installFonts();
823 return !m_error;
826 void RbUtilQt::installFonts()
828 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
829 RockboxInfo installInfo(mountpoint);
830 QString fontsurl;
831 QString logversion;
832 QString relversion = installInfo.release();
833 if(relversion.isEmpty()) {
834 // release is empty for non-release versions (i.e. daily / current)
835 fontsurl = SystemInfo::value(SystemInfo::DailyFontUrl).toString();
836 logversion = installInfo.revision();
838 else {
839 fontsurl = SystemInfo::value(SystemInfo::ReleaseFontUrl).toString();
840 logversion = installInfo.release();
842 fontsurl.replace("%RELEASEVER%", relversion);
844 // create zip installer
845 installer = new ZipInstaller(this);
846 installer->setUrl(fontsurl);
847 installer->setLogSection("Fonts");
848 installer->setLogVersion(logversion);
849 installer->setMountPoint(mountpoint);
850 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
851 installer->setCache(true);
853 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
854 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
855 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
856 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
857 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
858 installer->install();
862 void RbUtilQt::installVoice()
864 if(chkConfig(true)) return;
866 if(m_gotInfo == false)
868 QMessageBox::warning(this, tr("Warning"),
869 tr("The Application is still downloading Information about new Builds."
870 " Please try again shortly."));
871 return;
874 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
875 RockboxInfo installInfo(mountpoint);
877 QString voiceurl;
878 QString logversion;
879 QString relversion = installInfo.release();
880 // if no version is found abort.
881 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
882 QMessageBox::critical(this, tr("No Rockbox installation found"),
883 tr("Could not determine the installed Rockbox version. "
884 "Please install a Rockbox build before installing "
885 "voice files."));
886 return;
888 if(relversion.isEmpty()) {
889 // release is empty for non-release versions (i.e. daily / current)
890 voiceurl = SystemInfo::value(SystemInfo::DailyVoiceUrl).toString();
891 logversion = installInfo.revision();
893 else {
894 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
895 logversion = installInfo.release();
897 if(QMessageBox::question(this, tr("Confirm Installation"),
898 tr("Do you really want to install the voice file?"),
899 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
900 return;
902 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
903 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
904 // replace placeholder in voice url
905 voiceurl.replace("%DATE%", date.toString("yyyyMMdd"));
906 voiceurl.replace("%MODEL%", model);
907 voiceurl.replace("%RELVERSION%", relversion);
909 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
911 // create logger
912 logger = new ProgressLoggerGui(this);
913 logger->show();
914 // create zip installer
915 installer = new ZipInstaller(this);
917 installer->setUrl(voiceurl);
918 installer->setLogSection("Voice");
919 installer->setLogVersion(logversion);
920 installer->setMountPoint(mountpoint);
921 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
922 installer->setCache(true);
923 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
924 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
925 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
926 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
927 installer->install();
931 void RbUtilQt::installDoomBtn()
933 if(chkConfig(true)) return;
934 if(!hasDoom()){
935 QMessageBox::critical(this, tr("Error"),
936 tr("Your device doesn't have a doom plugin. Aborting."));
937 return;
940 if(QMessageBox::question(this, tr("Confirm Installation"),
941 tr("Do you really want to install the game addon files?"),
942 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
943 // create logger
944 logger = new ProgressLoggerGui(this);
945 logger->show();
947 installDoom();
949 bool RbUtilQt::installDoomAuto()
951 installDoom();
952 return !m_error;
955 bool RbUtilQt::hasDoom()
957 QFile doomrock(RbSettings::value(RbSettings::Mountpoint).toString()
958 +"/.rockbox/rocks/games/doom.rock");
959 return doomrock.exists();
962 void RbUtilQt::installDoom()
964 // create zip installer
965 installer = new ZipInstaller(this);
967 installer->setUrl(SystemInfo::value(SystemInfo::DoomUrl).toString());
968 installer->setLogSection("Game Addons");
969 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
970 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
971 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
972 installer->setCache(true);
973 connect(installer, SIGNAL(done(bool)), this, SLOT(installdone(bool)));
974 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
975 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
976 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
977 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
978 installer->install();
982 void RbUtilQt::installThemes()
984 if(chkConfig(true)) return;
985 ThemesInstallWindow* tw = new ThemesInstallWindow(this);
986 tw->setModal(true);
987 tw->show();
990 void RbUtilQt::createTalkFiles(void)
992 if(chkConfig(true)) return;
993 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
994 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
995 installWindow->show();
999 void RbUtilQt::createVoiceFile(void)
1001 if(chkConfig(true)) return;
1002 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
1004 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
1005 installWindow->show();
1008 void RbUtilQt::uninstall(void)
1010 if(chkConfig(true)) return;
1011 UninstallWindow *uninstallWindow = new UninstallWindow(this);
1012 uninstallWindow->show();
1016 void RbUtilQt::uninstallBootloader(void)
1018 if(chkConfig(true)) return;
1019 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
1020 tr("Do you really want to uninstall the Bootloader?"),
1021 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
1022 // create logger
1023 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1024 logger->setProgressVisible(false);
1025 logger->show();
1027 QString platform = RbSettings::value(RbSettings::Platform).toString();
1029 // create installer
1030 BootloaderInstallBase *bl = BootloaderInstallBase::createBootloaderInstaller(this,
1031 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
1033 if(bl == NULL ) {
1034 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
1035 logger->setFinished();
1036 return;
1038 if( (bl->capabilities() & BootloaderInstallBase::Uninstall) == 0)
1040 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target."
1041 "Try a normal firmware update to remove the booloader."), LOGERROR);
1042 logger->setFinished();
1043 delete bl;
1044 return;
1047 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
1048 QStringList blfilepath;
1049 for(int a = 0; a < blfile.size(); a++) {
1050 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
1051 + blfile.at(a));
1053 bl->setBlFile(blfilepath);
1055 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1056 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1058 int result;
1059 result = bl->uninstall();
1061 logger->setFinished();
1066 void RbUtilQt::downloadManual(void)
1068 if(chkConfig(true)) return;
1069 if(QMessageBox::question(this, tr("Confirm download"),
1070 tr("Do you really want to download the manual? The manual will be saved "
1071 "to the root folder of your player."),
1072 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1073 return;
1075 QString manual = SystemInfo::value(SystemInfo::CurManual).toString();
1076 if(manual.isEmpty())
1077 manual = "rockbox-"
1078 + SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
1080 QDate date = QDate::fromString(ServerInfo::value(ServerInfo::DailyDate).toString(),Qt::ISODate);
1082 QString manualurl;
1083 QString target;
1084 QString section;
1085 if(ui.radioPdf->isChecked()) {
1086 target = "/" + manual + ".pdf";
1087 section = "Manual (PDF)";
1089 else {
1090 target = "/" + manual + "-" + date.toString("yyyyMMdd") + "-html.zip";
1091 section = "Manual (HTML)";
1093 manualurl = SystemInfo::value(SystemInfo::ManualUrl).toString() + "/" + target;
1094 qDebug() << "[RbUtil] Manual URL:" << manualurl;
1096 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1097 logger->show();
1098 installer = new ZipInstaller(this);
1099 installer->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
1100 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
1101 installer->setCache(true);
1102 installer->setLogSection(section);
1103 installer->setLogVersion(ServerInfo::value(ServerInfo::DailyDate).toString());
1104 installer->setUrl(manualurl);
1105 installer->setUnzip(false);
1106 installer->setTarget(target);
1107 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
1108 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
1109 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
1110 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
1111 installer->install();
1115 void RbUtilQt::installPortable(void)
1117 if(QMessageBox::question(this, tr("Confirm installation"),
1118 tr("Do you really want to install Rockbox Utility to your player? "
1119 "After installation you can run it from the players hard drive."),
1120 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
1121 return;
1123 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
1124 logger->setProgressMax(0);
1125 logger->setProgressValue(0);
1126 logger->show();
1127 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
1129 // check mountpoint
1130 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
1131 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
1132 logger->setFinished();
1133 return;
1136 // remove old files first.
1137 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1138 + "/RockboxUtility.exe");
1139 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
1140 + "/RockboxUtility.ini");
1141 // copy currently running binary and currently used settings file
1142 if(!QFile::copy(qApp->applicationFilePath(),
1143 RbSettings::value(RbSettings::Mountpoint).toString()
1144 + "/RockboxUtility.exe")) {
1145 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
1146 logger->setFinished();
1147 return;
1149 logger->addItem(tr("Installing user configuration"), LOGINFO);
1150 if(!QFile::copy(RbSettings::userSettingFilename(),
1151 RbSettings::value(RbSettings::Mountpoint).toString()
1152 + "/RockboxUtility.ini")) {
1153 logger->addItem(tr("Error installing user configuration"), LOGERROR);
1154 logger->setFinished();
1155 return;
1157 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
1158 logger->setFinished();
1159 logger->setProgressMax(1);
1160 logger->setProgressValue(1);
1165 void RbUtilQt::updateInfo()
1167 qDebug() << "[RbUtil] updating server info";
1169 QString mp = RbSettings::value(RbSettings::Mountpoint).toString();
1170 QSettings log(mp + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
1171 QStringList groups = log.childGroups();
1172 QList<QTreeWidgetItem *> items;
1173 QTreeWidgetItem *w, *w2;
1174 QString min, max;
1175 int olditems = 0;
1177 // remove old list entries (if any)
1178 int l = ui.treeInfo->topLevelItemCount();
1179 while(l--) {
1180 QTreeWidgetItem *m;
1181 m = ui.treeInfo->takeTopLevelItem(l);
1182 // delete childs (single level deep, no recursion here)
1183 int n = m->childCount();
1184 while(n--)
1185 delete m->child(n);
1187 // get and populate new items
1188 for(int a = 0; a < groups.size(); a++) {
1189 log.beginGroup(groups.at(a));
1190 QStringList keys = log.allKeys();
1191 w = new QTreeWidgetItem;
1192 w->setFlags(Qt::ItemIsEnabled);
1193 w->setText(0, groups.at(a));
1194 items.append(w);
1195 // get minimum and maximum version information so we can hilight old files
1196 min = max = log.value(keys.at(0)).toString();
1197 for(int b = 0; b < keys.size(); b++) {
1198 if(log.value(keys.at(b)).toString() > max)
1199 max = log.value(keys.at(b)).toString();
1200 if(log.value(keys.at(b)).toString() < min)
1201 min = log.value(keys.at(b)).toString();
1204 for(int b = 0; b < keys.size(); b++) {
1205 QString file;
1206 file = mp + "/" + keys.at(b);
1207 if(QFileInfo(file).isDir())
1208 continue;
1209 w2 = new QTreeWidgetItem(w, QStringList() << "/"
1210 + keys.at(b) << log.value(keys.at(b)).toString());
1211 if(log.value(keys.at(b)).toString() != max) {
1212 w2->setForeground(0, QBrush(QColor(255, 0, 0)));
1213 w2->setForeground(1, QBrush(QColor(255, 0, 0)));
1214 olditems++;
1216 items.append(w2);
1218 log.endGroup();
1219 if(min != max)
1220 w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max));
1221 else
1222 w->setData(1, Qt::DisplayRole, max);
1224 ui.treeInfo->insertTopLevelItems(0, items);
1225 ui.treeInfo->resizeColumnToContents(0);
1229 QUrl RbUtilQt::proxy()
1231 if(RbSettings::value(RbSettings::ProxyType) == "manual")
1232 return QUrl(RbSettings::value(RbSettings::Proxy).toString());
1233 else if(RbSettings::value(RbSettings::ProxyType) == "system")
1234 return System::systemProxy();
1235 return QUrl("");
1239 bool RbUtilQt::chkConfig(bool warn)
1241 bool error = false;
1242 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
1243 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
1244 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
1245 error = true;
1247 if(warn) QMessageBox::critical(this, tr("Configuration error"),
1248 tr("Your configuration is invalid. Please go to the configuration "
1249 "dialog and make sure the selected values are correct."));
1251 return error;
1254 void RbUtilQt::checkUpdate(void)
1256 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1257 #if defined(Q_OS_WIN32)
1258 url += "win32/";
1259 #elif defined(Q_OS_LINUX)
1260 url += "linux/";
1261 #elif defined(Q_OS_MACX)
1262 url += "macosx/";
1263 #endif
1265 update = new HttpGet(this);
1266 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
1267 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
1268 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1269 update->setCache(true);
1271 update->getFile(QUrl(url));
1274 void RbUtilQt::downloadUpdateDone(bool error)
1276 if(error) {
1277 qDebug() << "[RbUtil] network error:" << update->error();
1279 else {
1280 QString toParse(update->readAll());
1282 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
1283 QStringList rbutilList;
1284 int pos = 0;
1285 while ((pos = searchString.indexIn(toParse, pos)) != -1)
1287 rbutilList << searchString.cap(1);
1288 pos += searchString.matchedLength();
1290 qDebug() << "[Checkupdate] " << rbutilList;
1292 QString newVersion ="";
1293 //check if there is a binary with higher version in this list
1294 for(int i=0; i < rbutilList.size(); i++)
1296 #if defined(Q_OS_LINUX)
1297 #if defined(__amd64__)
1298 //skip if it isnt a 64bit build
1299 if( !rbutilList.at(i).contains("64bit"))
1300 continue;
1301 #else
1302 //skip if it is a 64bit build
1303 if(rbutilList.at(i).contains("64bit"))
1304 continue;
1305 #endif
1306 #endif
1307 //check if it is newer, and remember newest
1308 if(newerVersion(VERSION,rbutilList.at(i)))
1310 if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i)))
1312 newVersion = rbutilList.at(i);
1317 // if we found something newer, display info
1318 if(newVersion != "")
1320 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
1321 #if defined(Q_OS_WIN32)
1322 url += "win32/";
1323 #elif defined(Q_OS_LINUX)
1324 url += "linux/";
1325 #elif defined(Q_OS_MACX)
1326 url += "macosx/";
1327 #endif
1328 url += newVersion;
1330 QMessageBox::information(this,tr("RockboxUtility Update available"),
1331 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1332 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
1337 bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
1339 QRegExp chars("\\d*(\\D)");
1341 //strip non-number from beginning
1342 versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
1343 versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
1345 // split versions by "."
1346 QStringList versionListOld = versionOld.split(".");
1347 QStringList versionListNew = versionNew.split(".");
1349 QStringListIterator iteratorOld(versionListOld);
1350 QStringListIterator iteratorNew(versionListNew);
1352 //check every section
1353 while(iteratorOld.hasNext() && iteratorNew.hasNext())
1355 QString newPart = iteratorNew.next();
1356 QString oldPart = iteratorOld.next();
1357 QString newPartChar = "", oldPartChar = "";
1358 int newPartInt = 0, oldPartInt =0;
1360 //convert to int, if it contains chars, put into seperated variable
1361 if(newPart.contains(chars))
1363 newPartChar = chars.cap(1);
1364 newPart = newPart.remove(newPartChar);
1366 newPartInt = newPart.toInt();
1367 //convert to int, if it contains chars, put into seperated variable
1368 if(oldPart.contains(chars))
1370 oldPartChar = chars.cap(1);
1371 oldPart = oldPart.remove(oldPartChar);
1373 oldPartInt = oldPart.toInt();
1375 if(newPartInt > oldPartInt) // this section int is higher -> true
1376 return true;
1377 else if(newPartInt < oldPartInt) //this section int is lower -> false
1378 return false;
1379 else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
1380 return true;
1381 else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
1382 return false;
1383 //all the same, next section
1385 // all the same -> false
1386 return false;