Handle language change events in widgets.
[maemo-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blobb1065936f7de30603588a4d883cdfbecd5f022b5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtGui>
21 #include "version.h"
22 #include "rbutilqt.h"
23 #include "ui_rbutilqtfrm.h"
24 #include "ui_aboutbox.h"
25 #include "configure.h"
26 #include "installtalkwindow.h"
27 #include "createvoicewindow.h"
28 #include "httpget.h"
29 #include "themesinstallwindow.h"
30 #include "uninstallwindow.h"
31 #include "utils.h"
32 #include "rockboxinfo.h"
33 #include "sysinfo.h"
34 #include "system.h"
35 #include "systrace.h"
36 #include "rbsettings.h"
37 #include "serverinfo.h"
38 #include "systeminfo.h"
39 #include "ziputil.h"
40 #include "manualwidget.h"
41 #include "infowidget.h"
42 #include "selectiveinstallwidget.h"
43 #include "backupdialog.h"
45 #include "progressloggerinterface.h"
47 #include "bootloaderinstallbase.h"
48 #include "bootloaderinstallhelper.h"
50 #if defined(Q_OS_LINUX)
51 #include <stdio.h>
52 #endif
53 #if defined(Q_OS_WIN32)
54 #if defined(UNICODE)
55 #define _UNICODE
56 #endif
57 #include <stdio.h>
58 #include <tchar.h>
59 #include <windows.h>
60 #endif
62 QList<QTranslator*> RbUtilQt::translators;
64 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
66 // startup log
67 qDebug() << "======================================";
68 qDebug() << "[System] Rockbox Utility " VERSION;
69 qDebug() << "[System] Qt version:" << qVersion();
70 qDebug() << "======================================";
72 absolutePath = qApp->applicationDirPath();
74 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
75 HttpGet::setGlobalProxy(proxy());
76 // init startup & autodetection
77 ui.setupUi(this);
78 #if defined(Q_OS_LINUX)
79 QIcon windowIcon(":/icons/rockbox-clef.svg");
80 this->setWindowIcon(windowIcon);
81 #endif
82 #if defined(Q_OS_WIN32)
83 QIcon windowIcon = QIcon();
84 windowIcon.addFile(":/icons/rockbox-16.png");
85 windowIcon.addFile(":/icons/rockbox-32.png");
86 windowIcon.addFile(":/icons/rockbox-48.png");
87 windowIcon.addFile(":/icons/rockbox-64.png");
88 windowIcon.addFile(":/icons/rockbox-128.png");
89 windowIcon.addFile(":/icons/rockbox-256.png");
90 this->setWindowIcon(windowIcon);
91 #endif
92 #if defined(Q_OS_MACX)
93 // don't translate menu entries that are handled specially on OS X
94 // (Configure, Quit). Qt handles them for us if they use english string.
95 ui.action_Configure->setText("Configure");
96 ui.actionE_xit->setText("Quit");
97 #endif
98 #if defined(Q_OS_WIN32)
99 long ret;
100 HKEY hk;
101 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Wine"),
102 0, KEY_QUERY_VALUE, &hk);
103 if(ret == ERROR_SUCCESS) {
104 QMessageBox::warning(this, tr("Wine detected!"),
105 tr("It seems you are trying to run this program under Wine. "
106 "Please don't do this, running under Wine will fail. "
107 "Use the native Linux binary instead."),
108 QMessageBox::Ok, QMessageBox::Ok);
109 qDebug() << "[RbUtil] WINE DETECTED!";
110 RegCloseKey(hk);
112 #endif
113 updateDevice();
114 downloadInfo();
116 m_gotInfo = false;
117 m_auto = false;
119 // insert ManualWidget() widget in manual tab
120 QGridLayout *mantablayout = new QGridLayout(this);
121 ui.manual->setLayout(mantablayout);
122 manual = new ManualWidget(this);
123 mantablayout->addWidget(manual);
125 // selective "install" tab.
126 QGridLayout *selectivetablayout = new QGridLayout(this);
127 ui.selective->setLayout(selectivetablayout);
128 selectiveinstallwidget = new SelectiveInstallWidget(this);
129 selectivetablayout->addWidget(selectiveinstallwidget);
130 connect(ui.buttonChangeDevice, SIGNAL(clicked()), selectiveinstallwidget, SLOT(saveSettings()));
132 // info tab
133 QGridLayout *infotablayout = new QGridLayout(this);
134 ui.info->setLayout(infotablayout);
135 info = new InfoWidget(this);
136 infotablayout->addWidget(info);
138 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
139 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
140 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
141 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
142 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
143 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
144 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
145 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
146 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
147 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
148 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
149 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
150 connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup()));
152 // actions accessible from the menu
153 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
154 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
155 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
156 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
157 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
158 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
159 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
161 #if !defined(STATIC)
162 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
163 #else
164 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
165 #endif
166 Utils::findRunningProcess(QStringList("iTunes"));
171 void RbUtilQt::shutdown(void)
173 // restore default message handler to prevent trace accesses during
174 // object destruction -- the trace object could already be destroyed.
175 // Fixes segfaults on exit.
176 qInstallMsgHandler(0);
177 SysTrace::save();
178 this->close();
182 void RbUtilQt::trace(void)
184 SysTrace wnd(this);
185 wnd.exec();
188 void RbUtilQt::sysinfo(void)
190 Sysinfo sysinfo(this);
191 sysinfo.exec();
194 void RbUtilQt::updateTabs(int count)
196 if(count == ui.tabWidget->indexOf(info->parentWidget()))
197 info->updateInfo();
201 void RbUtilQt::downloadInfo()
203 // try to get the current build information
204 daily = new HttpGet(this);
205 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
206 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
207 if(RbSettings::value(RbSettings::CacheOffline).toBool())
208 daily->setCache(true);
209 else
210 daily->setCache(false);
211 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
212 qDebug() << "[RbUtil] downloading build info";
213 daily->setFile(&buildInfo);
214 daily->getFile(QUrl(SystemInfo::value(SystemInfo::BuildInfoUrl).toString()));
218 void RbUtilQt::downloadDone(bool error)
220 if(error) {
221 qDebug() << "[RbUtil] network error:" << daily->error();
222 ui.statusbar->showMessage(tr("Can't get version information!"));
223 QMessageBox::critical(this, tr("Network error"),
224 tr("Can't get version information.\n"
225 "Network error: %1. Please check your network and proxy settings.")
226 .arg(daily->errorString()));
227 return;
229 qDebug() << "[RbUtil] network status:" << daily->error();
231 // read info into ServerInfo object
232 buildInfo.open();
233 ServerInfo::readBuildInfo(buildInfo.fileName());
234 buildInfo.close();
236 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
237 updateSettings();
238 m_gotInfo = true;
240 //start check for updates
241 checkUpdate();
246 void RbUtilQt::about()
248 QDialog *window = new QDialog(this);
249 Ui::aboutBox about;
250 about.setupUi(window);
251 window->setLayoutDirection(Qt::LeftToRight);
252 window->setModal(true);
254 QFile licence(":/docs/gpl-2.0.html");
255 licence.open(QIODevice::ReadOnly);
256 QTextStream c(&licence);
257 about.browserLicense->insertHtml(c.readAll());
258 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
260 QFile speexlicense(":/docs/COPYING.SPEEX");
261 speexlicense.open(QIODevice::ReadOnly);
262 QTextStream s(&speexlicense);
263 about.browserSpeexLicense->insertHtml("<pre>" + s.readAll() + "</pre>");
264 about.browserSpeexLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
266 QFile credits(":/docs/CREDITS");
267 credits.open(QIODevice::ReadOnly);
268 QTextStream r(&credits);
269 r.setCodec(QTextCodec::codecForName("UTF-8"));
270 while(!r.atEnd()) {
271 QString line = r.readLine();
272 // filter out header.
273 line.remove(QRegExp("^ +.*"));
274 line.remove(QRegExp("^People.*"));
275 about.browserCredits->append(line);
277 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
278 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
279 about.labelTitle->setText(title);
281 window->show();
286 void RbUtilQt::help()
288 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
289 QDesktopServices::openUrl(helpurl);
293 void RbUtilQt::configDialog()
295 Config *cw = new Config(this);
296 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
297 cw->show();
301 void RbUtilQt::updateSettings()
303 qDebug() << "[RbUtil] updating current settings";
304 updateDevice();
305 manual->updateManual();
306 HttpGet::setGlobalProxy(proxy());
307 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
308 HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
310 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
311 QApplication::processEvents();
312 QMessageBox::information(this, tr("New installation"),
313 tr("This is a new installation of Rockbox Utility, or a new version. "
314 "The configuration dialog will now open to allow you to setup the program, "
315 " or review your settings."));
316 configDialog();
318 else if(chkConfig(0)) {
319 QApplication::processEvents();
320 QMessageBox::critical(this, tr("Configuration error"),
321 tr("Your configuration is invalid. This is most likely due "
322 "to a changed device path. The configuration dialog will "
323 "now open to allow you to correct the problem."));
324 configDialog();
326 selectiveinstallwidget->updateVersion();
330 void RbUtilQt::updateDevice()
332 /* TODO: We should check the flags of the bootloaderinstall classes, and not
333 * just check if its != none or != "fwpatcher" */
335 /* Enable bootloader installation, if possible */
336 bool bootloaderInstallable =
337 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
339 /* Enable bootloader uninstallation, if possible */
340 bool bootloaderUninstallable = bootloaderInstallable &&
341 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
342 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
343 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
344 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
346 /* Disable the whole tab widget if configuration is invalid */
347 bool configurationValid = !chkConfig(0);
348 ui.tabWidget->setEnabled(configurationValid);
349 ui.menuA_ctions->setEnabled(configurationValid);
351 // displayed device info
352 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
353 QString name
354 = QString("%1 (%2)").arg(SystemInfo::value(SystemInfo::CurName).toString(),
355 ServerInfo::value(ServerInfo::CurStatus).toString());
356 ui.labelDevice->setText(tr("<b>%1 %2</b>").arg(brand, name));
358 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
359 QString mountdisplay = QDir::toNativeSeparators(mountpoint);
360 if(!mountdisplay.isEmpty()) {
361 QString label = Utils::filesystemName(mountpoint);
362 if(!label.isEmpty()) mountdisplay += QString(" (%1)").arg(label);
363 ui.labelMountpoint->setText(tr("<b>%1</b>").arg(mountdisplay));
365 else {
366 mountdisplay = "(unknown)";
369 QPixmap pm;
370 QString m = SystemInfo::value(SystemInfo::CurPlayerPicture).toString();
371 pm.load(":/icons/players/" + m + "-small.png");
372 pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3);
373 ui.labelPlayerPic->setPixmap(pm);
378 void RbUtilQt::backup(void)
380 backupdialog = new BackupDialog(this);
381 backupdialog->show();
386 void RbUtilQt::installdone(bool error)
388 qDebug() << "[RbUtil] install done";
389 m_installed = true;
390 m_error = error;
393 void RbUtilQt::installVoice()
395 if(chkConfig(this)) return;
397 if(m_gotInfo == false)
399 QMessageBox::warning(this, tr("Warning"),
400 tr("The Application is still downloading Information about new Builds."
401 " Please try again shortly."));
402 return;
405 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
406 RockboxInfo installInfo(mountpoint);
408 QString voiceurl;
409 QString logversion;
410 QString relversion = installInfo.release();
411 // if no version is found abort.
412 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
413 QMessageBox::critical(this, tr("No Rockbox installation found"),
414 tr("Could not determine the installed Rockbox version. "
415 "Please install a Rockbox build before installing "
416 "voice files."));
417 return;
419 if(relversion.isEmpty()) {
420 // release is empty for development builds.
421 // No voice files are available for development builds.
422 QMessageBox::critical(this, tr("No voice file available"),
423 tr("The installed version of Rockbox is a development version. "
424 "Pre-built voices are only available for release versions "
425 "of Rockbox. Please generate a voice yourself using the "
426 "\"Create voice file\" functionality."));
427 return;
429 else {
430 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
431 logversion = installInfo.release();
433 if(QMessageBox::question(this, tr("Confirm Installation"),
434 tr("Do you really want to install the voice file?"),
435 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
436 return;
438 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
439 // replace placeholder in voice url
440 voiceurl.replace("%MODEL%", model);
441 voiceurl.replace("%RELVERSION%", relversion);
443 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
445 // create logger
446 logger = new ProgressLoggerGui(this);
447 logger->show();
448 // create zip installer
449 installer = new ZipInstaller(this);
451 installer->setUrl(voiceurl);
452 installer->setLogSection("Voice");
453 installer->setLogVersion(logversion);
454 installer->setMountPoint(mountpoint);
455 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
456 installer->setCache(true);
457 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
458 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
459 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
460 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
461 installer->install();
466 void RbUtilQt::createTalkFiles(void)
468 if(chkConfig(this)) return;
469 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
470 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
471 installWindow->show();
475 void RbUtilQt::createVoiceFile(void)
477 if(chkConfig(this)) return;
478 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
480 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
481 installWindow->show();
484 void RbUtilQt::uninstall(void)
486 if(chkConfig(this)) return;
487 UninstallWindow *uninstallWindow = new UninstallWindow(this);
488 uninstallWindow->show();
492 void RbUtilQt::uninstallBootloader(void)
494 if(chkConfig(this)) return;
495 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
496 tr("Do you really want to uninstall the Bootloader?"),
497 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
498 // create logger
499 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
500 logger->setProgressVisible(false);
501 logger->show();
503 QString platform = RbSettings::value(RbSettings::Platform).toString();
505 // create installer
506 BootloaderInstallBase *bl
507 = BootloaderInstallHelper::createBootloaderInstaller(this,
508 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
510 if(bl == NULL) {
511 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
512 logger->setFinished();
513 return;
515 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
516 QStringList blfilepath;
517 for(int a = 0; a < blfile.size(); a++) {
518 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
519 + blfile.at(a));
521 bl->setBlFile(blfilepath);
523 BootloaderInstallBase::BootloaderType currentbl = bl->installed();
524 if((bl->capabilities() & BootloaderInstallBase::Uninstall) == 0
525 || currentbl == BootloaderInstallBase::BootloaderUnknown
526 || currentbl == BootloaderInstallBase::BootloaderOther)
528 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target. "
529 "Try a normal firmware update to remove the booloader."), LOGERROR);
530 logger->setFinished();
531 delete bl;
532 return;
535 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
536 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
538 bl->uninstall();
540 logger->setFinished();
545 void RbUtilQt::installPortable(void)
547 if(QMessageBox::question(this, tr("Confirm installation"),
548 tr("Do you really want to install Rockbox Utility to your player? "
549 "After installation you can run it from the players hard drive."),
550 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
551 return;
553 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
554 logger->setProgressMax(0);
555 logger->setProgressValue(0);
556 logger->show();
557 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
559 // check mountpoint
560 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
561 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
562 logger->setFinished();
563 return;
566 // remove old files first.
567 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
568 + "/RockboxUtility.exe");
569 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
570 + "/RockboxUtility.ini");
571 // copy currently running binary and currently used settings file
572 if(!QFile::copy(qApp->applicationFilePath(),
573 RbSettings::value(RbSettings::Mountpoint).toString()
574 + "/RockboxUtility.exe")) {
575 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
576 logger->setFinished();
577 return;
579 logger->addItem(tr("Installing user configuration"), LOGINFO);
580 if(!QFile::copy(RbSettings::userSettingFilename(),
581 RbSettings::value(RbSettings::Mountpoint).toString()
582 + "/RockboxUtility.ini")) {
583 logger->addItem(tr("Error installing user configuration"), LOGERROR);
584 logger->setFinished();
585 return;
587 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
588 logger->setFinished();
589 logger->setProgressMax(1);
590 logger->setProgressValue(1);
595 QUrl RbUtilQt::proxy()
597 QUrl proxy;
598 QString proxytype = RbSettings::value(RbSettings::ProxyType).toString();
599 if(proxytype == "manual")
600 proxy.setEncodedUrl(RbSettings::value(RbSettings::Proxy).toByteArray());
601 else if(proxytype == "system")
602 proxy = System::systemProxy();
604 qDebug() << "[RbUtilQt] Proxy is" << proxy;
605 return proxy;
609 bool RbUtilQt::chkConfig(QWidget *parent)
611 bool error = false;
612 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
613 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
614 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
615 error = true;
617 if(parent) QMessageBox::critical(parent, tr("Configuration error"),
618 tr("Your configuration is invalid. Please go to the configuration "
619 "dialog and make sure the selected values are correct."));
621 return error;
624 void RbUtilQt::checkUpdate(void)
626 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
627 #if defined(Q_OS_WIN32)
628 url += "win32/";
629 #elif defined(Q_OS_LINUX)
630 url += "linux/";
631 #elif defined(Q_OS_MACX)
632 url += "macosx/";
633 #endif
635 update = new HttpGet(this);
636 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
637 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
638 if(RbSettings::value(RbSettings::CacheOffline).toBool())
639 update->setCache(true);
641 ui.statusbar->showMessage(tr("Checking for update ..."));
642 update->getFile(QUrl(url));
645 void RbUtilQt::downloadUpdateDone(bool error)
647 if(error) {
648 qDebug() << "[RbUtil] network error:" << update->error();
650 else {
651 QString toParse(update->readAll());
653 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
654 QStringList rbutilList;
655 int pos = 0;
656 while ((pos = searchString.indexIn(toParse, pos)) != -1)
658 rbutilList << searchString.cap(1);
659 pos += searchString.matchedLength();
661 qDebug() << "[RbUtilQt] Checking for update";
663 QString newVersion = "";
664 QString foundVersion = "";
665 // check if there is a binary with higher version in this list
666 for(int i=0; i < rbutilList.size(); i++)
668 QString item = rbutilList.at(i);
669 #if defined(Q_OS_LINUX)
670 #if defined(__amd64__)
671 // skip if it isn't a 64 bit build
672 if( !item.contains("64bit"))
673 continue;
674 // strip the "64bit" suffix for comparison
675 item = item.remove("64bit");
676 #else
677 //skip if it is a 64bit build
678 if(item.contains("64bit"))
679 continue;
680 #endif
681 #endif
682 // check if it is newer, and remember newest
683 if(Utils::compareVersionStrings(VERSION, item) == 1)
685 if(Utils::compareVersionStrings(newVersion, item) == 1)
687 newVersion = item;
688 foundVersion = rbutilList.at(i);
693 // if we found something newer, display info
694 if(foundVersion != "")
696 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
697 #if defined(Q_OS_WIN32)
698 url += "win32/";
699 #elif defined(Q_OS_LINUX)
700 url += "linux/";
701 #elif defined(Q_OS_MACX)
702 url += "macosx/";
703 #endif
704 url += foundVersion;
706 QMessageBox::information(this,tr("RockboxUtility Update available"),
707 tr("<b>New RockboxUtility Version available.</b> <br><br>"
708 "Download it from here: <a href='%1'>%2</a>")
709 .arg(url).arg(foundVersion));
710 ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
712 else {
713 ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
719 void RbUtilQt::changeEvent(QEvent *e)
721 if(e->type() == QEvent::LanguageChange) {
722 ui.retranslateUi(this);
723 buildInfo.open();
724 ServerInfo::readBuildInfo(buildInfo.fileName());
725 buildInfo.close();
726 updateDevice();
727 } else {
728 QMainWindow::changeEvent(e);