aa0c365303eb69d514aad1aa1d3b7e152f7a90b7
[maemo-rb.git] / rbutil / rbutilqt / rbutilqt.cpp
blobaa0c365303eb69d514aad1aa1d3b7e152f7a90b7
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
114 #if !defined(Q_OS_WIN32)
115 /* eject funtionality is only implemented on W32 right now. */
116 ui.buttonEject->setEnabled(false);
117 #endif
118 updateDevice();
119 downloadInfo();
121 m_gotInfo = false;
122 m_auto = false;
124 // insert ManualWidget() widget in manual tab
125 QGridLayout *mantablayout = new QGridLayout(this);
126 ui.manual->setLayout(mantablayout);
127 manual = new ManualWidget(this);
128 mantablayout->addWidget(manual);
130 // selective "install" tab.
131 QGridLayout *selectivetablayout = new QGridLayout(this);
132 ui.selective->setLayout(selectivetablayout);
133 selectiveinstallwidget = new SelectiveInstallWidget(this);
134 selectivetablayout->addWidget(selectiveinstallwidget);
135 connect(ui.buttonChangeDevice, SIGNAL(clicked()), selectiveinstallwidget, SLOT(saveSettings()));
137 // info tab
138 QGridLayout *infotablayout = new QGridLayout(this);
139 ui.info->setLayout(infotablayout);
140 info = new InfoWidget(this);
141 infotablayout->addWidget(info);
143 connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
144 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
145 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
146 connect(ui.action_Help, SIGNAL(triggered()), this, SLOT(help()));
147 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
148 connect(ui.actionE_xit, SIGNAL(triggered()), this, SLOT(shutdown()));
149 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
150 connect(ui.buttonEject, SIGNAL(clicked()), this, SLOT(eject()));
151 connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles()));
152 connect(ui.buttonCreateVoice, SIGNAL(clicked()), this, SLOT(createVoiceFile()));
153 connect(ui.buttonVoice, SIGNAL(clicked()), this, SLOT(installVoice()));
154 connect(ui.buttonRemoveRockbox, SIGNAL(clicked()), this, SLOT(uninstall()));
155 connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader()));
156 connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup()));
158 // actions accessible from the menu
159 connect(ui.actionInstall_Voice_File, SIGNAL(triggered()), this, SLOT(installVoice()));
160 connect(ui.actionCreate_Voice_File, SIGNAL(triggered()), this, SLOT(createVoiceFile()));
161 connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles()));
162 connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader()));
163 connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall()));
164 connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo()));
165 connect(ui.action_Trace, SIGNAL(triggered()), this, SLOT(trace()));
167 #if !defined(STATIC)
168 ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false);
169 #else
170 connect(ui.actionInstall_Rockbox_Utility_on_player, SIGNAL(triggered()), this, SLOT(installPortable()));
171 #endif
172 Utils::findRunningProcess(QStringList("iTunes"));
177 void RbUtilQt::shutdown(void)
179 // restore default message handler to prevent trace accesses during
180 // object destruction -- the trace object could already be destroyed.
181 // Fixes segfaults on exit.
182 qInstallMsgHandler(0);
183 SysTrace::save();
184 this->close();
188 void RbUtilQt::trace(void)
190 SysTrace wnd(this);
191 wnd.exec();
194 void RbUtilQt::sysinfo(void)
196 Sysinfo sysinfo(this);
197 sysinfo.exec();
200 void RbUtilQt::updateTabs(int count)
202 if(count == ui.tabWidget->indexOf(info->parentWidget()))
203 info->updateInfo();
207 void RbUtilQt::downloadInfo()
209 // try to get the current build information
210 daily = new HttpGet(this);
211 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
212 connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort()));
213 if(RbSettings::value(RbSettings::CacheOffline).toBool())
214 daily->setCache(true);
215 else
216 daily->setCache(false);
217 ui.statusbar->showMessage(tr("Downloading build information, please wait ..."));
218 qDebug() << "[RbUtil] downloading build info";
219 daily->setFile(&buildInfo);
220 daily->getFile(QUrl(SystemInfo::value(SystemInfo::BuildInfoUrl).toString()));
224 void RbUtilQt::downloadDone(bool error)
226 if(error) {
227 qDebug() << "[RbUtil] network error:" << daily->error();
228 ui.statusbar->showMessage(tr("Can't get version information!"));
229 QMessageBox::critical(this, tr("Network error"),
230 tr("Can't get version information.\n"
231 "Network error: %1. Please check your network and proxy settings.")
232 .arg(daily->errorString()));
233 return;
235 qDebug() << "[RbUtil] network status:" << daily->error();
237 // read info into ServerInfo object
238 buildInfo.open();
239 ServerInfo::readBuildInfo(buildInfo.fileName());
240 buildInfo.close();
242 ui.statusbar->showMessage(tr("Download build information finished."), 5000);
243 updateSettings();
244 m_gotInfo = true;
246 //start check for updates
247 checkUpdate();
252 void RbUtilQt::about()
254 QDialog *window = new QDialog(this);
255 Ui::aboutBox about;
256 about.setupUi(window);
257 window->setLayoutDirection(Qt::LeftToRight);
258 window->setModal(true);
260 QFile licence(":/docs/gpl-2.0.html");
261 licence.open(QIODevice::ReadOnly);
262 QTextStream c(&licence);
263 about.browserLicense->insertHtml(c.readAll());
264 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
266 QFile speexlicense(":/docs/COPYING.SPEEX");
267 speexlicense.open(QIODevice::ReadOnly);
268 QTextStream s(&speexlicense);
269 about.browserSpeexLicense->insertHtml("<pre>" + s.readAll() + "</pre>");
270 about.browserSpeexLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
272 QFile credits(":/docs/CREDITS");
273 credits.open(QIODevice::ReadOnly);
274 QTextStream r(&credits);
275 r.setCodec(QTextCodec::codecForName("UTF-8"));
276 while(!r.atEnd()) {
277 QString line = r.readLine();
278 // filter out header.
279 line.remove(QRegExp("^ +.*"));
280 line.remove(QRegExp("^People.*"));
281 about.browserCredits->append(line);
283 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
284 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
285 about.labelTitle->setText(title);
287 window->show();
292 void RbUtilQt::help()
294 QUrl helpurl("http://www.rockbox.org/wiki/RockboxUtility");
295 QDesktopServices::openUrl(helpurl);
299 void RbUtilQt::configDialog()
301 Config *cw = new Config(this);
302 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
303 cw->show();
307 void RbUtilQt::updateSettings()
309 qDebug() << "[RbUtil] updating current settings";
310 updateDevice();
311 manual->updateManual();
312 HttpGet::setGlobalProxy(proxy());
313 HttpGet::setGlobalCache(RbSettings::value(RbSettings::CachePath).toString());
314 HttpGet::setGlobalDumbCache(RbSettings::value(RbSettings::CacheOffline).toBool());
316 if(RbSettings::value(RbSettings::RbutilVersion) != PUREVERSION) {
317 QApplication::processEvents();
318 QMessageBox::information(this, tr("New installation"),
319 tr("This is a new installation of Rockbox Utility, or a new version. "
320 "The configuration dialog will now open to allow you to setup the program, "
321 " or review your settings."));
322 configDialog();
324 else if(chkConfig(0)) {
325 QApplication::processEvents();
326 QMessageBox::critical(this, tr("Configuration error"),
327 tr("Your configuration is invalid. This is most likely due "
328 "to a changed device path. The configuration dialog will "
329 "now open to allow you to correct the problem."));
330 configDialog();
332 selectiveinstallwidget->updateVersion();
336 void RbUtilQt::updateDevice()
338 /* TODO: We should check the flags of the bootloaderinstall classes, and not
339 * just check if its != none or != "fwpatcher" */
341 /* Enable bootloader installation, if possible */
342 bool bootloaderInstallable =
343 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "none";
345 /* Enable bootloader uninstallation, if possible */
346 bool bootloaderUninstallable = bootloaderInstallable &&
347 SystemInfo::value(SystemInfo::CurBootloaderMethod) != "fwpatcher";
348 ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable);
349 ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable);
350 ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable);
352 /* Disable the whole tab widget if configuration is invalid */
353 bool configurationValid = !chkConfig(0);
354 ui.tabWidget->setEnabled(configurationValid);
355 ui.menuA_ctions->setEnabled(configurationValid);
357 // displayed device info
358 QString brand = SystemInfo::value(SystemInfo::CurBrand).toString();
359 QString name
360 = QString("%1 (%2)").arg(SystemInfo::value(SystemInfo::CurName).toString(),
361 ServerInfo::value(ServerInfo::CurStatus).toString());
362 ui.labelDevice->setText(QString("<b>%1 %2</b>").arg(brand, name));
364 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
365 QString mountdisplay = QDir::toNativeSeparators(mountpoint);
366 if(!mountdisplay.isEmpty()) {
367 QString label = Utils::filesystemName(mountpoint);
368 if(!label.isEmpty()) mountdisplay += QString(" (%1)").arg(label);
369 ui.labelMountpoint->setText(QString("<b>%1</b>").arg(mountdisplay));
371 else {
372 mountdisplay = "(unknown)";
375 QPixmap pm;
376 QString m = SystemInfo::value(SystemInfo::CurPlayerPicture).toString();
377 pm.load(":/icons/players/" + m + "-small.png");
378 pm = pm.scaledToHeight(QFontMetrics(QApplication::font()).height() * 3);
379 ui.labelPlayerPic->setPixmap(pm);
384 void RbUtilQt::backup(void)
386 backupdialog = new BackupDialog(this);
387 backupdialog->show();
392 void RbUtilQt::installdone(bool error)
394 qDebug() << "[RbUtil] install done";
395 m_installed = true;
396 m_error = error;
399 void RbUtilQt::installVoice()
401 if(chkConfig(this)) return;
403 if(m_gotInfo == false)
405 QMessageBox::warning(this, tr("Warning"),
406 tr("The Application is still downloading Information about new Builds."
407 " Please try again shortly."));
408 return;
411 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
412 RockboxInfo installInfo(mountpoint);
414 QString voiceurl;
415 QString logversion;
416 QString relversion = installInfo.release();
417 // if no version is found abort.
418 if(installInfo.revision().isEmpty() && relversion.isEmpty()) {
419 QMessageBox::critical(this, tr("No Rockbox installation found"),
420 tr("Could not determine the installed Rockbox version. "
421 "Please install a Rockbox build before installing "
422 "voice files."));
423 return;
425 if(relversion.isEmpty()) {
426 // release is empty for development builds.
427 // No voice files are available for development builds.
428 QMessageBox::critical(this, tr("No voice file available"),
429 tr("The installed version of Rockbox is a development version. "
430 "Pre-built voices are only available for release versions "
431 "of Rockbox. Please generate a voice yourself using the "
432 "\"Create voice file\" functionality."));
433 return;
435 else {
436 voiceurl = SystemInfo::value(SystemInfo::ReleaseVoiceUrl).toString();
437 logversion = installInfo.release();
439 if(QMessageBox::question(this, tr("Confirm Installation"),
440 tr("Do you really want to install the voice file?"),
441 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
442 return;
444 QString model = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
445 // replace placeholder in voice url
446 voiceurl.replace("%MODEL%", model);
447 voiceurl.replace("%RELVERSION%", relversion);
449 qDebug() << "[RbUtil] voicefile URL:" << voiceurl;
451 // create logger
452 logger = new ProgressLoggerGui(this);
453 logger->show();
454 // create zip installer
455 installer = new ZipInstaller(this);
457 installer->setUrl(voiceurl);
458 installer->setLogSection("Voice");
459 installer->setLogVersion(logversion);
460 installer->setMountPoint(mountpoint);
461 if(!RbSettings::value(RbSettings::CacheDisabled).toBool())
462 installer->setCache(true);
463 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
464 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
465 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
466 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
467 installer->install();
472 void RbUtilQt::createTalkFiles(void)
474 if(chkConfig(this)) return;
475 InstallTalkWindow *installWindow = new InstallTalkWindow(this);
476 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
477 installWindow->show();
481 void RbUtilQt::createVoiceFile(void)
483 if(chkConfig(this)) return;
484 CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
486 connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
487 installWindow->show();
490 void RbUtilQt::uninstall(void)
492 if(chkConfig(this)) return;
493 UninstallWindow *uninstallWindow = new UninstallWindow(this);
494 uninstallWindow->show();
498 void RbUtilQt::uninstallBootloader(void)
500 if(chkConfig(this)) return;
501 if(QMessageBox::question(this, tr("Confirm Uninstallation"),
502 tr("Do you really want to uninstall the Bootloader?"),
503 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;
504 // create logger
505 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
506 logger->setProgressVisible(false);
507 logger->show();
509 QString platform = RbSettings::value(RbSettings::Platform).toString();
511 // create installer
512 BootloaderInstallBase *bl
513 = BootloaderInstallHelper::createBootloaderInstaller(this,
514 SystemInfo::value(SystemInfo::CurBootloaderMethod).toString());
516 if(bl == NULL) {
517 logger->addItem(tr("No uninstall method for this target known."), LOGERROR);
518 logger->setFinished();
519 return;
521 QStringList blfile = SystemInfo::value(SystemInfo::CurBootloaderFile).toStringList();
522 QStringList blfilepath;
523 for(int a = 0; a < blfile.size(); a++) {
524 blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString()
525 + blfile.at(a));
527 bl->setBlFile(blfilepath);
529 BootloaderInstallBase::BootloaderType currentbl = bl->installed();
530 if((bl->capabilities() & BootloaderInstallBase::Uninstall) == 0) {
531 logger->addItem(tr("Rockbox Utility can not uninstall the bootloader on this target. "
532 "Try a normal firmware update to remove the booloader."), LOGERROR);
533 logger->setFinished();
534 delete bl;
535 return;
537 if(currentbl == BootloaderInstallBase::BootloaderUnknown
538 || currentbl == BootloaderInstallBase::BootloaderOther) {
539 logger->addItem(tr("No Rockbox bootloader found."), LOGERROR);
540 logger->setFinished();
541 delete bl;
542 return;
545 connect(bl, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
546 connect(bl, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
548 bl->uninstall();
550 logger->setFinished();
555 void RbUtilQt::installPortable(void)
557 if(QMessageBox::question(this, tr("Confirm installation"),
558 tr("Do you really want to install Rockbox Utility to your player? "
559 "After installation you can run it from the players hard drive."),
560 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
561 return;
563 ProgressLoggerGui* logger = new ProgressLoggerGui(this);
564 logger->setProgressMax(0);
565 logger->setProgressValue(0);
566 logger->show();
567 logger->addItem(tr("Installing Rockbox Utility"), LOGINFO);
569 // check mountpoint
570 if(!QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isDir()) {
571 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
572 logger->setFinished();
573 return;
576 // remove old files first.
577 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
578 + "/RockboxUtility.exe");
579 QFile::remove(RbSettings::value(RbSettings::Mountpoint).toString()
580 + "/RockboxUtility.ini");
581 // copy currently running binary and currently used settings file
582 if(!QFile::copy(qApp->applicationFilePath(),
583 RbSettings::value(RbSettings::Mountpoint).toString()
584 + "/RockboxUtility.exe")) {
585 logger->addItem(tr("Error installing Rockbox Utility"), LOGERROR);
586 logger->setFinished();
587 return;
589 logger->addItem(tr("Installing user configuration"), LOGINFO);
590 if(!QFile::copy(RbSettings::userSettingFilename(),
591 RbSettings::value(RbSettings::Mountpoint).toString()
592 + "/RockboxUtility.ini")) {
593 logger->addItem(tr("Error installing user configuration"), LOGERROR);
594 logger->setFinished();
595 return;
597 logger->addItem(tr("Successfully installed Rockbox Utility."), LOGOK);
598 logger->setFinished();
599 logger->setProgressMax(1);
600 logger->setProgressValue(1);
605 QUrl RbUtilQt::proxy()
607 QUrl proxy;
608 QString proxytype = RbSettings::value(RbSettings::ProxyType).toString();
609 if(proxytype == "manual")
610 proxy.setEncodedUrl(RbSettings::value(RbSettings::Proxy).toByteArray());
611 else if(proxytype == "system")
612 proxy = System::systemProxy();
614 qDebug() << "[RbUtilQt] Proxy is" << proxy;
615 return proxy;
619 bool RbUtilQt::chkConfig(QWidget *parent)
621 bool error = false;
622 if(RbSettings::value(RbSettings::Platform).toString().isEmpty()
623 || RbSettings::value(RbSettings::Mountpoint).toString().isEmpty()
624 || !QFileInfo(RbSettings::value(RbSettings::Mountpoint).toString()).isWritable()) {
625 error = true;
627 if(parent) QMessageBox::critical(parent, tr("Configuration error"),
628 tr("Your configuration is invalid. Please go to the configuration "
629 "dialog and make sure the selected values are correct."));
631 return error;
634 void RbUtilQt::checkUpdate(void)
636 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
637 #if defined(Q_OS_WIN32)
638 url += "win32/";
639 #elif defined(Q_OS_LINUX)
640 url += "linux/";
641 #elif defined(Q_OS_MACX)
642 url += "macosx/";
643 #endif
645 update = new HttpGet(this);
646 connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool)));
647 connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort()));
648 if(RbSettings::value(RbSettings::CacheOffline).toBool())
649 update->setCache(true);
651 ui.statusbar->showMessage(tr("Checking for update ..."));
652 update->getFile(QUrl(url));
655 void RbUtilQt::downloadUpdateDone(bool error)
657 if(error) {
658 qDebug() << "[RbUtil] network error:" << update->error();
660 else {
661 QString toParse(update->readAll());
663 QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>");
664 QStringList rbutilList;
665 int pos = 0;
666 while ((pos = searchString.indexIn(toParse, pos)) != -1)
668 rbutilList << searchString.cap(1);
669 pos += searchString.matchedLength();
671 qDebug() << "[RbUtilQt] Checking for update";
673 QString newVersion = "";
674 QString foundVersion = "";
675 // check if there is a binary with higher version in this list
676 for(int i=0; i < rbutilList.size(); i++)
678 QString item = rbutilList.at(i);
679 #if defined(Q_OS_LINUX)
680 #if defined(__amd64__)
681 // skip if it isn't a 64 bit build
682 if( !item.contains("64bit"))
683 continue;
684 // strip the "64bit" suffix for comparison
685 item = item.remove("64bit");
686 #else
687 //skip if it is a 64bit build
688 if(item.contains("64bit"))
689 continue;
690 #endif
691 #endif
692 // check if it is newer, and remember newest
693 if(Utils::compareVersionStrings(VERSION, item) == 1)
695 if(Utils::compareVersionStrings(newVersion, item) == 1)
697 newVersion = item;
698 foundVersion = rbutilList.at(i);
703 // if we found something newer, display info
704 if(foundVersion != "")
706 QString url = SystemInfo::value(SystemInfo::RbutilUrl).toString();
707 #if defined(Q_OS_WIN32)
708 url += "win32/";
709 #elif defined(Q_OS_LINUX)
710 url += "linux/";
711 #elif defined(Q_OS_MACX)
712 url += "macosx/";
713 #endif
714 url += foundVersion;
716 QMessageBox::information(this,tr("RockboxUtility Update available"),
717 tr("<b>New RockboxUtility Version available.</b> <br><br>"
718 "Download it from here: <a href='%1'>%2</a>")
719 .arg(url).arg(foundVersion));
720 ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
722 else {
723 ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
729 void RbUtilQt::changeEvent(QEvent *e)
731 if(e->type() == QEvent::LanguageChange) {
732 ui.retranslateUi(this);
733 buildInfo.open();
734 ServerInfo::readBuildInfo(buildInfo.fileName());
735 buildInfo.close();
736 updateDevice();
737 } else {
738 QMainWindow::changeEvent(e);
742 void RbUtilQt::eject(void)
744 QString mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
745 if(Utils::ejectDevice(mountpoint)) {
746 QMessageBox::information(this, tr("Device ejected"),
747 tr("Device successfully ejected. "
748 "You may now disconnect the player from the PC."));
750 else {
751 QMessageBox::critical(this, tr("Ejecting failed"),
752 tr("Ejecting the device failed. Please make sure no programs "
753 "are accessing files on the device. If ejecting still "
754 "fails please use your computers eject funtionality."));