mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-27 07:46:24 -04:00
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:
parent
e6c0bd0350
commit
e30b3d84e8
4 changed files with 160 additions and 94 deletions
|
|
@ -38,6 +38,7 @@ bool Autodetection::detect()
|
||||||
m_device = "";
|
m_device = "";
|
||||||
m_mountpoint = "";
|
m_mountpoint = "";
|
||||||
m_errdev = "";
|
m_errdev = "";
|
||||||
|
m_usberr = "";
|
||||||
|
|
||||||
detectUsb();
|
detectUsb();
|
||||||
|
|
||||||
|
|
@ -146,7 +147,8 @@ bool Autodetection::detect()
|
||||||
// if the found ipod is a macpod also notice it as device with problem.
|
// if the found ipod is a macpod also notice it as device with problem.
|
||||||
if(ipod.macpod)
|
if(ipod.macpod)
|
||||||
m_errdev = ipod.targetname;
|
m_errdev = ipod.targetname;
|
||||||
m_device = ipod.targetname;
|
else
|
||||||
|
m_device = ipod.targetname;
|
||||||
// since resolveMountPoint is doing exact matches we need to select
|
// since resolveMountPoint is doing exact matches we need to select
|
||||||
// the correct partition.
|
// the correct partition.
|
||||||
QString mp(ipod.diskname);
|
QString mp(ipod.diskname);
|
||||||
|
|
@ -218,8 +220,8 @@ bool Autodetection::detectUsb()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(usberror.contains(attached.at(i))) {
|
if(usberror.contains(attached.at(i))) {
|
||||||
m_errdev = usberror.value(attached.at(i)).at(0);
|
m_usberr = usberror.value(attached.at(i)).at(0);
|
||||||
qDebug() << "[USB] detected problem with player" << m_errdev;
|
qDebug() << "[USB] detected problem with player" << m_usberr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0'));
|
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)
|
bool Autodetection::detectAjbrec(QString root)
|
||||||
{
|
{
|
||||||
QFile f(root + "/ajbrec.ajz");
|
QFile f(root + "/ajbrec.ajz");
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,34 @@ class Autodetection :public QObject
|
||||||
public:
|
public:
|
||||||
Autodetection(QObject* parent=0);
|
Autodetection(QObject* parent=0);
|
||||||
|
|
||||||
|
enum PlayerStatus {
|
||||||
|
PlayerOk,
|
||||||
|
PlayerIncompatible,
|
||||||
|
PlayerMtpMode,
|
||||||
|
PlayerWrongFilesystem,
|
||||||
|
PlayerError,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Detected {
|
||||||
|
QString device;
|
||||||
|
QString mountpoint;
|
||||||
|
enum PlayerStatus status;
|
||||||
|
};
|
||||||
|
|
||||||
bool detect();
|
bool detect();
|
||||||
|
|
||||||
QString getDevice() {return m_device;}
|
QList<struct Detected> detected(void);
|
||||||
QString getMountPoint() {return m_mountpoint;}
|
|
||||||
QString errdev(void) { return m_errdev; }
|
|
||||||
QString incompatdev(void) { return m_incompat; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString resolveMountPoint(QString);
|
QString resolveMountPoint(QString);
|
||||||
bool detectUsb(void);
|
bool detectUsb(void);
|
||||||
bool detectAjbrec(QString);
|
bool detectAjbrec(QString);
|
||||||
|
|
||||||
|
QList<struct Detected> m_detected;
|
||||||
QString m_device;
|
QString m_device;
|
||||||
QString m_mountpoint;
|
QString m_mountpoint;
|
||||||
QString m_errdev;
|
QString m_errdev;
|
||||||
|
QString m_usberr;
|
||||||
QString m_incompat;
|
QString m_incompat;
|
||||||
QList<int> m_usbconid;
|
QList<int> m_usbconid;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -725,98 +725,117 @@ void Config::autodetect()
|
||||||
this->setCursor(Qt::WaitCursor);
|
this->setCursor(Qt::WaitCursor);
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
if(detector.detect()) //let it detect
|
detector.detect();
|
||||||
{
|
QList<struct Autodetection::Detected> detected;
|
||||||
QString devicename = detector.getDevice();
|
detected = detector.detected();
|
||||||
// deexpand all items
|
this->unsetCursor();
|
||||||
for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
|
if(detected.size() > 1) {
|
||||||
ui.treeDevices->topLevelItem(a)->setExpanded(false);
|
// FIXME: handle multiple found players.
|
||||||
//deselect the selected item(s)
|
QMessageBox::information(this, tr("Device Detection"),
|
||||||
for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
|
tr("Multiple devices have been detected. Please disconnect "
|
||||||
ui.treeDevices->selectedItems().at(a)->setSelected(false);
|
"all players but one and try again."));
|
||||||
|
ui.treeDevices->setEnabled(true);
|
||||||
// find the new item
|
|
||||||
// enumerate all platform items
|
|
||||||
QList<QTreeWidgetItem*> itmList
|
|
||||||
= ui.treeDevices->findItems("*",Qt::MatchWildcard);
|
|
||||||
for(int i=0; i< itmList.size();i++)
|
|
||||||
{
|
|
||||||
//enumerate device items
|
|
||||||
for(int j=0;j < itmList.at(i)->childCount();j++)
|
|
||||||
{
|
|
||||||
QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
|
|
||||||
// unset bold flag
|
|
||||||
QFont f = itmList.at(i)->child(j)->font(0);
|
|
||||||
f.setBold(false);
|
|
||||||
itmList.at(i)->child(j)->setFont(0, f);
|
|
||||||
|
|
||||||
if(devicename == data) // item found
|
|
||||||
{
|
|
||||||
f.setBold(true);
|
|
||||||
itmList.at(i)->child(j)->setFont(0, f);
|
|
||||||
itmList.at(i)->child(j)->setSelected(true); //select the item
|
|
||||||
itmList.at(i)->setExpanded(true); //expand the platform item
|
|
||||||
//ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
|
|
||||||
ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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() != "" )
|
|
||||||
{
|
|
||||||
setMountpoint(detector.getMountPoint());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::warning(this, tr("Autodetection"),
|
|
||||||
tr("Could not detect a Mountpoint.\n"
|
|
||||||
"Select your Mountpoint manually."),
|
|
||||||
QMessageBox::Ok ,QMessageBox::Ok);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if(detected.size() == 0) {
|
||||||
{
|
QMessageBox::warning(this, tr("Device Detection"),
|
||||||
this->unsetCursor();
|
|
||||||
QMessageBox::warning(this, tr("Autodetection"),
|
|
||||||
tr("Could not detect a device.\n"
|
tr("Could not detect a device.\n"
|
||||||
"Select your device and Mountpoint manually."),
|
"Select your device and Mountpoint manually."),
|
||||||
QMessageBox::Ok ,QMessageBox::Ok);
|
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)
|
||||||
|
for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
|
||||||
|
ui.treeDevices->selectedItems().at(a)->setSelected(false);
|
||||||
|
|
||||||
|
// find the new item
|
||||||
|
// enumerate all platform items
|
||||||
|
QList<QTreeWidgetItem*> itmList
|
||||||
|
= ui.treeDevices->findItems("*",Qt::MatchWildcard);
|
||||||
|
for(int i=0; i< itmList.size();i++)
|
||||||
|
{
|
||||||
|
//enumerate device items
|
||||||
|
for(int j=0;j < itmList.at(i)->childCount();j++)
|
||||||
|
{
|
||||||
|
QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
|
||||||
|
// unset bold flag
|
||||||
|
QFont f = itmList.at(i)->child(j)->font(0);
|
||||||
|
f.setBold(false);
|
||||||
|
itmList.at(i)->child(j)->setFont(0, f);
|
||||||
|
|
||||||
|
if(device == data) // item found
|
||||||
|
{
|
||||||
|
f.setBold(true);
|
||||||
|
itmList.at(i)->child(j)->setFont(0, f);
|
||||||
|
itmList.at(i)->child(j)->setSelected(true); //select the item
|
||||||
|
itmList.at(i)->setExpanded(true); //expand the platform item
|
||||||
|
//ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
|
||||||
|
ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->unsetCursor();
|
||||||
|
|
||||||
|
if(!mountpoint.isEmpty())
|
||||||
|
{
|
||||||
|
setMountpoint(mountpoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Autodetection"),
|
||||||
|
tr("Could not detect a Mountpoint.\n"
|
||||||
|
"Select your Mountpoint manually."),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
}
|
}
|
||||||
ui.treeDevices->setEnabled(true);
|
ui.treeDevices->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ class Config : public QDialog
|
||||||
QString mountpoint;
|
QString mountpoint;
|
||||||
void updateCacheInfo(QString);
|
void updateCacheInfo(QString);
|
||||||
void changeEvent(QEvent *event);
|
void changeEvent(QEvent *event);
|
||||||
|
void selectDevice(QString device, QString mountpoint);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showProxyPassword(bool show);
|
void showProxyPassword(bool show);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue