Change autodetection result to a list.

Both autodetection functionality and the configuration dialog assumed detection
to only return one found device. This isn't necessarily true, especially since
some players can be detected but detecting their mountpoint might be ambiguous
(only if no previous Rockbox installation is present).

Instead of returning individual results (found "ok" player, found "error"
player etc.) return a list containing an entry for each player. Current
autodetection code will never return more than one entry since it doesn't
handle multiple devices yet, and the configuration dialog will show an error if
multiple devices are found. Thus there is no user visible change yet. Both
autodetection and configuration dialog can now get extended to handle multiple
devices.

Change-Id: I79b763dbd6e7111783194bcc22ab7cc06a4061c1
This commit is contained in:
Dominik Riebeling 2013-04-06 21:15:05 +02:00
parent e6c0bd0350
commit e30b3d84e8
4 changed files with 160 additions and 94 deletions

View file

@ -38,6 +38,7 @@ bool Autodetection::detect()
m_device = "";
m_mountpoint = "";
m_errdev = "";
m_usberr = "";
detectUsb();
@ -146,6 +147,7 @@ bool Autodetection::detect()
// if the found ipod is a macpod also notice it as device with problem.
if(ipod.macpod)
m_errdev = ipod.targetname;
else
m_device = ipod.targetname;
// since resolveMountPoint is doing exact matches we need to select
// the correct partition.
@ -218,8 +220,8 @@ bool Autodetection::detectUsb()
return true;
}
if(usberror.contains(attached.at(i))) {
m_errdev = usberror.value(attached.at(i)).at(0);
qDebug() << "[USB] detected problem with player" << m_errdev;
m_usberr = usberror.value(attached.at(i)).at(0);
qDebug() << "[USB] detected problem with player" << m_usberr;
return true;
}
QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0'));
@ -233,6 +235,37 @@ bool Autodetection::detectUsb()
}
QList<struct Autodetection::Detected> Autodetection::detected(void)
{
struct Detected d;
m_detected.clear();
if(!m_device.isEmpty()) {
d.device = m_device;
d.mountpoint = m_mountpoint;
d.status = PlayerOk;
m_detected.append(d);
}
else if(!m_errdev.isEmpty()) {
d.device = m_errdev;
d.status = PlayerWrongFilesystem;
m_detected.append(d);
}
else if(!m_usberr.isEmpty()) {
d.device = m_usberr;
d.status = PlayerMtpMode;
m_detected.append(d);
}
else if(!m_incompat.isEmpty()) {
d.device = m_incompat;
d.status = PlayerIncompatible;
m_detected.append(d);
}
return m_detected;
}
bool Autodetection::detectAjbrec(QString root)
{
QFile f(root + "/ajbrec.ajz");

View file

@ -33,21 +33,34 @@ class Autodetection :public QObject
public:
Autodetection(QObject* parent=0);
enum PlayerStatus {
PlayerOk,
PlayerIncompatible,
PlayerMtpMode,
PlayerWrongFilesystem,
PlayerError,
};
struct Detected {
QString device;
QString mountpoint;
enum PlayerStatus status;
};
bool detect();
QString getDevice() {return m_device;}
QString getMountPoint() {return m_mountpoint;}
QString errdev(void) { return m_errdev; }
QString incompatdev(void) { return m_incompat; }
QList<struct Detected> detected(void);
private:
QString resolveMountPoint(QString);
bool detectUsb(void);
bool detectAjbrec(QString);
QList<struct Detected> m_detected;
QString m_device;
QString m_mountpoint;
QString m_errdev;
QString m_usberr;
QString m_incompat;
QList<int> m_usbconid;
};

View file

@ -725,13 +725,75 @@ void Config::autodetect()
this->setCursor(Qt::WaitCursor);
QCoreApplication::processEvents();
if(detector.detect()) //let it detect
{
QString devicename = detector.getDevice();
// deexpand all items
detector.detect();
QList<struct Autodetection::Detected> detected;
detected = detector.detected();
this->unsetCursor();
if(detected.size() > 1) {
// FIXME: handle multiple found players.
QMessageBox::information(this, tr("Device Detection"),
tr("Multiple devices have been detected. Please disconnect "
"all players but one and try again."));
ui.treeDevices->setEnabled(true);
}
else if(detected.size() == 0) {
QMessageBox::warning(this, tr("Device Detection"),
tr("Could not detect a device.\n"
"Select your device and Mountpoint manually."),
QMessageBox::Ok ,QMessageBox::Ok);
ui.treeDevices->setEnabled(true);
}
else if(detected.at(0).status != Autodetection::PlayerOk) {
QString msg;
switch(detected.at(0).status) {
case Autodetection::PlayerIncompatible:
msg += tr("Detected an unsupported player:\n%1\n"
"Sorry, Rockbox doesn't run on your player.")
.arg(SystemInfo::platformValue(detected.at(0).device,
SystemInfo::CurName).toString());
break;
case Autodetection::PlayerMtpMode:
msg = tr("%1 in MTP mode found!\n"
"You need to change your player to MSC mode for installation. ")
.arg(SystemInfo::platformValue(detected.at(0).device,
SystemInfo::CurName).toString());
break;
case Autodetection::PlayerWrongFilesystem:
if(SystemInfo::platformValue(detected.at(0).device,
SystemInfo::CurBootloaderMethod) == "ipod") {
msg = tr("%1 \"MacPod\" found!\n"
"Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
"to run. ").arg(SystemInfo::platformValue(
detected.at(0).device, SystemInfo::CurName).toString());
}
else {
msg = tr("The player contains an incompatible filesystem.\n"
"Make sure you selected the correct mountpoint and "
"the player is set up to use a filesystem compatible "
"with Rockbox.");
}
break;
case Autodetection::PlayerError:
msg += tr("An unknown error occured during player detection.");
break;
default:
break;
}
QMessageBox::information(this, tr("Device Detection"), msg);
ui.treeDevices->setEnabled(true);
}
else {
selectDevice(detected.at(0).device, detected.at(0).mountpoint);
}
}
void Config::selectDevice(QString device, QString mountpoint)
{
// collapse all items
for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
ui.treeDevices->topLevelItem(a)->setExpanded(false);
//deselect the selected item(s)
// deselect the selected item(s)
for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
ui.treeDevices->selectedItems().at(a)->setSelected(false);
@ -750,7 +812,7 @@ void Config::autodetect()
f.setBold(false);
itmList.at(i)->child(j)->setFont(0, f);
if(devicename == data) // item found
if(device == data) // item found
{
f.setBold(true);
itmList.at(i)->child(j)->setFont(0, f);
@ -764,59 +826,16 @@ void Config::autodetect()
}
this->unsetCursor();
if(!detector.errdev().isEmpty()) {
QString text;
if(SystemInfo::platformValue(detector.errdev(),
SystemInfo::CurBootloaderMethod) == "ipod") {
text = tr("%1 \"MacPod\" found!\n"
"Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
"to run. ").arg(SystemInfo::platformValue(
detector.errdev(), SystemInfo::CurName).toString());
}
// treat all other errors as MTP device for now.
else {
text = tr("%1 in MTP mode found!\n"
"You need to change your player to MSC mode for installation. ")
.arg(SystemInfo::platformValue(detector.errdev(),
SystemInfo::CurName).toString());
}
text += tr("Until you change this installation will fail!");
QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
return;
}
if(!detector.incompatdev().isEmpty()) {
QString text;
text = tr("Detected an unsupported player:\n%1\n"
"Sorry, Rockbox doesn't run on your player.")
.arg(SystemInfo::platformValue(detector.incompatdev(),
SystemInfo::CurName).toString());
QMessageBox::critical(this, tr("Fatal: player incompatible"),
text, QMessageBox::Ok);
return;
}
if(detector.getMountPoint() != "" )
if(!mountpoint.isEmpty())
{
setMountpoint(detector.getMountPoint());
setMountpoint(mountpoint);
}
else
{
QMessageBox::warning(this, tr("Autodetection"),
tr("Could not detect a Mountpoint.\n"
"Select your Mountpoint manually."),
QMessageBox::Ok ,QMessageBox::Ok);
}
}
else
{
this->unsetCursor();
QMessageBox::warning(this, tr("Autodetection"),
tr("Could not detect a device.\n"
"Select your device and Mountpoint manually."),
QMessageBox::Ok ,QMessageBox::Ok);
QMessageBox::Ok, QMessageBox::Ok);
}
ui.treeDevices->setEnabled(true);
}

View file

@ -54,6 +54,7 @@ class Config : public QDialog
QString mountpoint;
void updateCacheInfo(QString);
void changeEvent(QEvent *event);
void selectDevice(QString device, QString mountpoint);
private slots:
void showProxyPassword(bool show);