Sort bulgarian.lang into english.lang order
[maemo-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blobc5cdeb1cf7167d4f2ce98fc2b9711c5dabd91db3
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 <QMainWindow>
20 #include <QMessageBox>
22 #include "version.h"
23 #include "rbutilqt.h"
24 #include "ui_rbutilqtfrm.h"
25 #include "ui_aboutbox.h"
26 #include "configure.h"
27 #include "installtalkwindow.h"
28 #include "createvoicewindow.h"
29 #include "httpget.h"
30 #include "themesinstallwindow.h"
31 #include "uninstallwindow.h"
32 #include "utils.h"
33 #include "rockboxinfo.h"
34 #include "sysinfo.h"
35 #include "system.h"
36 #include "systrace.h"
37 #include "rbsettings.h"
38 #include "serverinfo.h"
39 #include "systeminfo.h"
40 #include "ziputil.h"
41 #include "manualwidget.h"
42 #include "infowidget.h"
43 #include "selectiveinstallwidget.h"
44 #include "backupdialog.h"
46 #include "progressloggerinterface.h"
48 #include "bootloaderinstallbase.h"
49 #include "bootloaderinstallhelper.h"
51 #if defined(Q_OS_LINUX)
52 #include <stdio.h>
53 #endif
54 #if defined(Q_OS_WIN32)
55 #if defined(UNICODE)
56 #define _UNICODE
57 #endif
58 #include <stdio.h>
59 #include <tchar.h>
60 #include <windows.h>
61 #endif
63 QList<QTranslator*> RbUtilQt::translators;
65 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
67 // startup log
68 qDebug() << "======================================";
69 qDebug() << "[System] Rockbox Utility " VERSION;
70 qDebug() << "[System] Qt version:" << qVersion();
71 qDebug() << "======================================";
73 absolutePath = qApp->applicationDirPath();
75 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
76 HttpGet::setGlobalProxy(proxy());
77 // init startup & autodetection
78 ui.setupUi(this);
79 #if defined(Q_OS_LINUX)
80 QIcon windowIcon(":/icons/rockbox-clef.svg");
81 this->setWindowIcon(windowIcon);
82 #endif
83 #if defined(Q_OS_WIN32)
84 QIcon windowIcon = QIcon();
85 windowIcon.addFile(":/icons/rockbox-16.png");
86 windowIcon.addFile(":/icons/rockbox-32.png");
87 windowIcon.addFile(":/icons/rockbox-48.png");
88 windowIcon.addFile(":/icons/rockbox-64.png");
89 windowIcon.addFile(":/icons/rockbox-128.png");
90 windowIcon.addFile(":/icons/rockbox-256.png");
91 this->setWindowIcon(windowIcon);
92 #endif
93 #if defined(Q_OS_MACX)
94 // don't translate menu entries that are handled specially on OS X
95 // (Configure, Quit). Qt handles them for us if they use english string.
96 ui.action_Configure->setText("Configure");
97 ui.actionE_xit->setText("Quit");
98 #endif
99 #if defined(Q_OS_WIN32)
100 long ret;
101 HKEY hk;
102 ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Wine"),
103 0, KEY_QUERY_VALUE, &hk);
104 if(ret == ERROR_SUCCESS) {
105 QMessageBox::warning(this, tr("Wine detected!"),
106 tr("It seems you are trying to run this program under Wine. "
107 "Please don't do this, running under Wine will fail. "
108 "Use the native Linux binary instead."),
109 QMessageBox::Ok, QMessageBox::Ok);
110 qDebug() << "[RbUtil] WINE DETECTED!";
111 RegCloseKey(hk);
113 #endif
115 #if !defined(Q_OS_WIN32) && !defined(Q_OS_MACX)
116 /* eject funtionality is only implemented on W32 right now. */
117 ui.buttonEject->setEnabled(false);
118 #endif
119 QString c = RbSettings::value(RbSettings::CachePath).toString();
120 if(c.isEmpty()) c = QDir::tempPath();
121 HttpGet::setGlobalCache(c);
122 updateDevice();
123 downloadInfo();
125 m_gotInfo = false;
126 m_auto = false;
128 // insert ManualWidget() widget in manual tab
129 QGridLayout *mantablayout = new QGridLayout(this);
130 ui.manual->setLayout(mantablayout);
131 manual = new ManualWidget(this);
132 mantablayout->addWidget(manual);
134 // selective "install" tab.
135 QGridLayout *selectivetablayout = new QGridLayout(this);
136 ui.selective->setLayout(selectivetablayout);
137 selectiveinstallwidget = new SelectiveInstallWidget(this);
138 selectivetablayout->addWidget(selectiveinstallwidget);
139 connect(ui.buttonChangeDevice, SIGNAL(clicked()), selectiveinstallwidget, SLOT(saveSettings()));
141 // info tab
142 QGridLayout *infotablayout = new QGridLayout(this);
143 ui.info->setLayout(infotablayout);
144 info = new InfoWidget(this);
145 infotablayout->addWidget(info);
147 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
148 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
149 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
150 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
151 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
152 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
153 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
154 connect(ui.buttonEject, SIGNAL(clicked()), this, SLOT(eject()));
155 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
156 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
157 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
158 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
159 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
160 connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup()));
162 // actions accessible from the menu
163 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
164 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
165 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
166 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
167 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
168 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
169 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
171 #if !defined(STATIC)
172 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
173 #else
174 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
175 #endif
176 Utils::findRunningProcess(QStringList("iTunes"));
181 void RbUtilQt::shutdown(void)
183 // restore default message handler to prevent trace accesses during
184 // object destruction -- the trace object could already be destroyed.
185 // Fixes segfaults on exit.
186 #if QT_VERSION < 0x050000
187 qInstallMsgHandler(0);
188 #else
189 qInstallMessageHandler(0);
190 #endif
191 SysTrace::save();
192 this->close();
196 void RbUtilQt::trace(void)
198 SysTrace wnd(this);
199 wnd.exec();
202 void RbUtilQt::sysinfo(void)
204 Sysinfo sysinfo(this);
205 sysinfo.exec();
208 void RbUtilQt::updateTabs(int count)
210 if(count == ui.tabWidget->indexOf(info->parentWidget()))
211 info->updateInfo();
215 void RbUtilQt::downloadInfo()
217 // try to get the current build information
218 daily = new HttpGet(this);
219 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
220 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
221 daily->setCache(false);
222 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
223 qDebug() << "[RbUtil] downloading build info";
224 daily->setFile(&buildInfo);
225 daily->getFile(QUrl(SystemInfo::value(SystemInfo::BuildInfoUrl).toString()));
229 void RbUtilQt::downloadDone(bool error)
231 if(error) {
232 qDebug() << "[RbUtil] network error:" << daily->errorString();
233 ui.statusbar->showMessage(tr("Can't get version information!"));
234 QMessageBox::critical(this, tr("Network error"),
235 tr("Can't get version information.\n"
236 "Network error: %1. Please check your network and proxy settings.")
237 .arg(daily->errorString()));
238 return;
240 qDebug() << "[RbUtil] network status:" << daily->errorString();
242 // read info into ServerInfo object
243 buildInfo.open();
244 ServerInfo::readBuildInfo(buildInfo.fileName());
245 buildInfo.close();
247 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
248 updateSettings();
249 m_gotInfo = true;
251 //start check for updates
252 checkUpdate();
257 void RbUtilQt::about()
259 QDialog *window = new QDialog(this);
260 Ui::aboutBox about;
261 about.setupUi(window);
262 window->setLayoutDirection(Qt::LeftToRight);
263 window->setModal(true);
265 QFile licence(":/docs/gpl-2.0.html");
266 licence.open(QIODevice::ReadOnly);
267 QTextStream c(&licence);
268 about.browserLicense->insertHtml(c.readAll());
269 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
271 QFile speexlicense(":/docs/COPYING.SPEEX");
272 speexlicense.open(QIODevice::ReadOnly);
273 QTextStream s(&speexlicense);
274 about.browserSpeexLicense->insertHtml("<pre>" + s.readAll() + "</pre>");
275 about.browserSpeexLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
277 QFile credits(":/docs/CREDITS");
278 credits.open(QIODevice::ReadOnly);
279 QTextStream r(&credits);
280 r.setCodec(QTextCodec::codecForName("UTF-8"));
281 while(!r.atEnd()) {
282 QString line = r.readLine();
283 // filter out header.
284 line.remove(QRegExp("^ +.*"));
285 line.remove(QRegExp("^People.*"));
286 about.browserCredits->append(line);
288 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
289 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
290 about.labelTitle->setText(title);
292 window->show();
297 void RbUtilQt::help()
299 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
300 QDesktopServices::openUrl(helpurl);
304 void RbUtilQt::configDialog()
306 Config *cw = new Config(this);
307 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
308 cw->show();
312 void RbUtilQt::updateSettings()
314 qDebug() << "[RbUtil] updating current settings";
315 updateDevice();
316 manual->updateManual();
317 HttpGet::setGlobalProxy(proxy());
318 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
320 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
321 QApplication::processEvents();
322 QMessageBox::information(this, tr("New installation"),
323 tr("This is a new installation of Rockbox Utility, or a new version. "
324 "The configuration dialog will now open to allow you to setup the program, "
325 " or review your settings."));
326 configDialog();
328 else if(chkConfig(0)) {
329 QApplication::processEvents();
330 QMessageBox::critical(this, tr("Configuration error"),
331 tr("Your configuration is invalid. This is most likely due "
332 "to a changed device path. The configuration dialog will "
333 "now open to allow you to correct the problem."));
334 configDialog();
336 selectiveinstallwidget->updateVersion();
340 void RbUtilQt::updateDevice()
342 /* TODO: We should check the flags of the bootloaderinstall classes, and not
343 * just check if its != none or != "fwpatcher" */
345 /* Enable bootloader installation, if possible */
346 bool bootloaderInstallable =
347 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
349 /* Enable bootloader uninstallation, if possible */
350 bool bootloaderUninstallable = bootloaderInstallable &&
351 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
352 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
353 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
354 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
356 /* Disable the whole tab widget if configuration is invalid */
357 bool configurationValid = !chkConfig(0);
358 ui.tabWidget->setEnabled(configurationValid);
359 ui.menuA_ctions->setEnabled(configurationValid);
361 // displayed device info
362 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
363 QString name
364 = QString("%1 (%2)").arg(SystemInfo::value(SystemInfo::CurName).toString(),
365 ServerInfo::value(ServerInfo::CurStatus).toString());
366 ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name));
368 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
369 QString mountdisplay = QDir::toNativeSeparators(mountpoint);
370 if(!mountdisplay.isEmpty()) {
371 QString label = Utils::filesystemName(mountpoint);
372 if(!label.isEmpty()) mountdisplay += QString(" (%1)").arg(label);
373 ui.labelMountpoint->setText(QString("<b>%1</b>").arg(mountdisplay));
375 else {
376 mountdisplay = "(unknown)";
379 QPixmap pm;
380 QString m = SystemInfo::value(SystemInfo::CurPlayerPicture).toString();
381 pm.load(":/icons/players/" + m + "-small.png");
382 pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3);
383 ui.labelPlayerPic->setPixmap(pm);
388 void RbUtilQt::backup(void)
390 backupdialog = new BackupDialog(this);
391 backupdialog->show();
396 void RbUtilQt::installdone(bool error)
398 qDebug() << "[RbUtil] install done";
399 m_installed = true;
400 m_error = error;
403 void RbUtilQt::installVoice()
405 if(chkConfig(this)) return;
407 if(m_gotInfo == false)
409 QMessageBox::warning(this, tr("Warning"),
410 tr("The Application is still downloading Information about new Builds."
411 " Please try again shortly."));
412 return;
415 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
416 RockboxInfo installInfo(mountpoint);
418 QString voiceurl;
419 QString logversion;
420 QString relversion = installInfo.release();
421 // if no version is found abort.
422 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
423 QMessageBox::critical(this, tr("No Rockbox installation found"),
424 tr("Could not determine the installed Rockbox version. "
425 "Please install a Rockbox build before installing "
426 "voice files."));
427 return;
429 if(relversion.isEmpty()) {
430 // release is empty for development builds.
431 // No voice files are available for development builds.
432 QMessageBox::critical(this, tr("No voice file available"),
433 tr("The installed version of Rockbox is a development version. "
434 "Pre-built voices are only available for release versions "
435 "of Rockbox. Please generate a voice yourself using the "
436 "\"Create voice file\" functionality."));
437 return;
439 else {
440 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
441 logversion = installInfo.release();
443 if(QMessageBox::question(this, tr("Confirm Installation"),
444 tr("Do you really want to install the voice file?"),
445 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
446 return;
448 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
449 // replace placeholder in voice url
450 voiceurl.replace("%MODEL%", model);
451 voiceurl.replace("%RELVERSION%", relversion);
453 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
455 // create logger
456 logger = new ProgressLoggerGui(this);
457 logger->show();
458 // create zip installer
459 installer = new ZipInstaller(this);
461 installer->setUrl(voiceurl);
462 installer->setLogSection("Voice");
463 installer->setLogVersion(logversion);
464 installer->setMountPoint(mountpoint);
465 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
466 installer->setCache(true);
467 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
468 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
469 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
470 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
471 installer->install();
476 void RbUtilQt::createTalkFiles(void)
478 if(chkConfig(this)) return;
479 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
480 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
481 installWindow->show();
485 void RbUtilQt::createVoiceFile(void)
487 if(chkConfig(this)) return;
488 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
490 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
491 installWindow->show();
494 void RbUtilQt::uninstall(void)
496 if(chkConfig(this)) return;
497 UninstallWindow *uninstallWindow = new UninstallWindow(this);
498 uninstallWindow->show();
502 void RbUtilQt::uninstallBootloader(void)
504 if(chkConfig(this)) return;
505 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
506 tr("Do you really want to uninstall the Bootloader?"),
507 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
508 // create logger
509 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
510 logger->setProgressVisible(false);
511 logger->show();
513 QString platform = RbSettings::value(RbSettings::Platform).toString();
515 // create installer
516 BootloaderInstallBase *bl
517 = BootloaderInstallHelper::createBootloaderInstaller(this,
518 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
520 if(bl == NULL) {
521 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
522 logger->setFinished();
523 return;
525 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
526 QStringList blfilepath;
527 for(int a = 0; a < blfile.size(); a++) {
528 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
529 + blfile.at(a));
531 bl->setBlFile(blfilepath);
533 BootloaderInstallBase::BootloaderType currentbl = bl->installed();
534 if((bl->capabilities() & BootloaderInstallBase::Uninstall) == 0) {
535 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target. "
536 "Try a normal firmware update to remove the booloader."), LOGERROR);
537 logger->setFinished();
538 delete bl;
539 return;
541 if(currentbl == BootloaderInstallBase::BootloaderUnknown
542 || currentbl == BootloaderInstallBase::BootloaderOther) {
543 logger->addItem(tr("No Rockbox bootloader found."), LOGERROR);
544 logger->setFinished();
545 delete bl;
546 return;
549 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
550 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
552 bl->uninstall();
554 logger->setFinished();
559 void RbUtilQt::installPortable(void)
561 if(QMessageBox::question(this, tr("Confirm installation"),
562 tr("Do you really want to install Rockbox Utility to your player? "
563 "After installation you can run it from the players hard drive."),
564 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
565 return;
567 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
568 logger->setProgressMax(0);
569 logger->setProgressValue(0);
570 logger->show();
571 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
573 // check mountpoint
574 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
575 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
576 logger->setFinished();
577 return;
580 // remove old files first.
581 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
582 + "/RockboxUtility.exe");
583 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
584 + "/RockboxUtility.ini");
585 // copy currently running binary and currently used settings file
586 if(!QFile::copy(qApp->applicationFilePath(),
587 RbSettings::value(RbSettings::Mountpoint).toString()
588 + "/RockboxUtility.exe")) {
589 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
590 logger->setFinished();
591 return;
593 logger->addItem(tr("Installing user configuration"), LOGINFO);
594 if(!QFile::copy(RbSettings::userSettingFilename(),
595 RbSettings::value(RbSettings::Mountpoint).toString()
596 + "/RockboxUtility.ini")) {
597 logger->addItem(tr("Error installing user configuration"), LOGERROR);
598 logger->setFinished();
599 return;
601 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
602 logger->setFinished();
603 logger->setProgressMax(1);
604 logger->setProgressValue(1);
609 QUrl RbUtilQt::proxy()
611 QUrl proxy;
612 QString proxytype = RbSettings::value(RbSettings::ProxyType).toString();
613 if(proxytype == "manual")
614 proxy.setEncodedUrl(RbSettings::value(RbSettings::Proxy).toByteArray());
615 else if(proxytype == "system")
616 proxy = System::systemProxy();
618 qDebug() << "[RbUtilQt] Proxy is" << proxy;
619 return proxy;
623 bool RbUtilQt::chkConfig(QWidget *parent)
625 bool error = false;
626 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
627 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
628 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
629 error = true;
631 if(parent) QMessageBox::critical(parent, tr("Configuration error"),
632 tr("Your configuration is invalid. Please go to the configuration "
633 "dialog and make sure the selected values are correct."));
635 return error;
638 void RbUtilQt::checkUpdate(void)
640 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
641 #if defined(Q_OS_WIN32)
642 url += "win32/";
643 #elif defined(Q_OS_LINUX)
644 url += "linux/";
645 #elif defined(Q_OS_MACX)
646 url += "macosx/";
647 #endif
649 update = new HttpGet(this);
650 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
651 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
653 ui.statusbar->showMessage(tr("Checking for update ..."));
654 update->getFile(QUrl(url));
657 void RbUtilQt::downloadUpdateDone(bool error)
659 if(error) {
660 qDebug() << "[RbUtil] network error:" << update->errorString();
662 else {
663 QString toParse(update->readAll());
665 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
666 QStringList rbutilList;
667 int pos = 0;
668 while ((pos = searchString.indexIn(toParse, pos)) != -1)
670 rbutilList << searchString.cap(1);
671 pos += searchString.matchedLength();
673 qDebug() << "[RbUtilQt] Checking for update";
675 QString newVersion = "";
676 QString foundVersion = "";
677 // check if there is a binary with higher version in this list
678 for(int i=0; i < rbutilList.size(); i++)
680 QString item = rbutilList.at(i);
681 #if defined(Q_OS_LINUX)
682 #if defined(__amd64__)
683 // skip if it isn't a 64 bit build
684 if( !item.contains("64bit"))
685 continue;
686 // strip the "64bit" suffix for comparison
687 item = item.remove("64bit");
688 #else
689 //skip if it is a 64bit build
690 if(item.contains("64bit"))
691 continue;
692 #endif
693 #endif
694 // check if it is newer, and remember newest
695 if(Utils::compareVersionStrings(VERSION, item) == 1)
697 if(Utils::compareVersionStrings(newVersion, item) == 1)
699 newVersion = item;
700 foundVersion = rbutilList.at(i);
705 // if we found something newer, display info
706 if(foundVersion != "")
708 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
709 #if defined(Q_OS_WIN32)
710 url += "win32/";
711 #elif defined(Q_OS_LINUX)
712 url += "linux/";
713 #elif defined(Q_OS_MACX)
714 url += "macosx/";
715 #endif
716 url += foundVersion;
718 QMessageBox::information(this,tr("RockboxUtility Update available"),
719 tr("<b>New RockboxUtility Version available.</b> <br><br>"
720 "Download it from here: <a href='%1'>%2</a>")
721 .arg(url).arg(foundVersion));
722 ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
724 else {
725 ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
731 void RbUtilQt::changeEvent(QEvent *e)
733 if(e->type() == QEvent::LanguageChange) {
734 ui.retranslateUi(this);
735 buildInfo.open();
736 ServerInfo::readBuildInfo(buildInfo.fileName());
737 buildInfo.close();
738 updateDevice();
739 } else {
740 QMainWindow::changeEvent(e);
744 void RbUtilQt::eject(void)
746 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
747 if(Utils::ejectDevice(mountpoint)) {
748 QMessageBox::information(this, tr("Device ejected"),
749 tr("Device successfully ejected. "
750 "You may now disconnect the player from the PC."));
752 else {
753 QMessageBox::critical(this, tr("Ejecting failed"),
754 tr("Ejecting the device failed. Please make sure no programs "
755 "are accessing files on the device. If ejecting still "
756 "fails please use your computers eject funtionality."));