Index: rbutil/rbutilqt/autodetectionfrm.cpp =================================================================== --- rbutil/rbutilqt/autodetectionfrm.cpp (revision 0) +++ rbutil/rbutilqt/autodetectionfrm.cpp (revision 0) @@ -0,0 +1,155 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "autodetectionfrm.h" +#include "rbsettings.h" + +AutodetectionFrm::AutodetectionFrm(QDialog* parent) : QDialog(parent) +{ + ui.setupUi(this); + connect(ui.buttonOk,SIGNAL(clicked()),this,SLOT(accept())); + connect(ui.buttonCancel,SIGNAL(clicked()),this,SLOT(reject())); +} + + +bool AutodetectionFrm::scan() +{ + // show splash screen + QSplashScreen splash(this,QPixmap(":/icons/rblogo.png")); + splash.show(); + splash.showMessage("Scanning System...",Qt::AlignRight,Qt::red); + QCoreApplication::processEvents(); + Autodetection detector(this); + detector.scan(); + m_deviceList = detector.getDevices(); + //Hide splash screen + splash.finish(this); + + //setup the window + setUpWindow(); + + //execute dialog + return this->exec(); +} + +void AutodetectionFrm::setUpWindow() +{ + //layout + QGridLayout *mainLayout = new QGridLayout; + mainLayout->setVerticalSpacing(2); + mainLayout->setHorizontalSpacing(2); + // for every device + for(int i=0; i< m_deviceList.size();i++) + { + DeviceGui device; + + // checkbox to select the device + device.select = new QRadioButton(this); + if(m_deviceList.size() == 1) device.select->setChecked(true); + device.select->setMaximumSize(15,20); + mainLayout->addWidget(device.select,i,0,1,1); + // combobox for the targetnames TODO replace with nice target names + if(m_deviceList[i].targets.size() > 1) + { + device.targets = new QComboBox(this); + ((QComboBox*)device.targets)->addItems(m_deviceList[i].targets); + } + else if(m_deviceList[i].targets.size() == 1) + { + device.targets = new QLineEdit(m_deviceList[i].targets.at(0),this); + ((QLineEdit*)device.targets)->setReadOnly(true); + } + else + { + QString idstring = QString("%1").arg(m_deviceList[i].usbid, 8, 16, QChar('0')); + device.targets = new QLineEdit(RbSettings::platformValue(idstring, RbSettings::CurName).toString(),this); + ((QLineEdit*)device.targets)->setReadOnly(true); + } + + device.targets->setMaximumHeight(20); + mainLayout->addWidget(device.targets,i,1,1,2); + //combobox for mountpoints + if(m_deviceList[i].mountpoints.size() > 1) + { + device.mountpoints = new QComboBox(this); + ((QComboBox*)device.mountpoints)->addItems(m_deviceList[i].mountpoints); + } + else if(m_deviceList[i].mountpoints.size() == 1) + device.mountpoints = new QLineEdit(m_deviceList[i].mountpoints.at(0),this); + else + device.mountpoints = new QLineEdit("",this); + + device.mountpoints->setMaximumHeight(20); + mainLayout->addWidget(device.mountpoints,i,3,1,2); + //add browser button + device.browse = new QPushButton("Browse",this); + device.browse->setMaximumHeight(20); + mainLayout->addWidget(device.browse,i,5,1,1); + //add Label for status + device.state = new QLabel(m_deviceList[i].errstring,this); + if(m_deviceList[i].state == Device::Ok) + ((QLabel*)device.state)->setPixmap(QPixmap(":icons/go-next.png")); + else if(m_deviceList[i].state == Device::Warning) + ((QLabel*)device.state)->setPixmap(QPixmap(":icons/dialog-warning.png")); + else + ((QLabel*)device.state)->setPixmap(QPixmap(":icons/dialog-error.png")); + device.state->setMaximumHeight(20); + mainLayout->addWidget(device.state,i,6,1,1); + + m_deviceGui.append(device); + } + ui.deviceBox->setLayout(mainLayout); + ui.deviceBox->updateGeometry(); +} + + +void AutodetectionFrm::accept(void) +{ + //find selected entry + for(int i=0; i < m_deviceGui.size();i++) + { + if(m_deviceGui[i].select->isChecked()) + { + if(m_deviceGui[i].targets->inherits("QLineEdit")) + m_target = ((QLineEdit*)m_deviceGui[i].targets)->text(); + else + m_target = ((QComboBox*)m_deviceGui[i].targets)->currentText(); + + if(m_deviceGui[i].mountpoints->inherits("QLineEdit")) + m_mountpoint = ((QLineEdit*)m_deviceGui[i].mountpoints)->text(); + else + m_mountpoint = ((QComboBox*)m_deviceGui[i].mountpoints)->currentText(); + + } + + } + + this->done(1); +} + +void AutodetectionFrm::reject(void) +{ + this->done(0); +} + + + + Index: rbutil/rbutilqt/autodetectionfrm.h =================================================================== --- rbutil/rbutilqt/autodetectionfrm.h (revision 0) +++ rbutil/rbutilqt/autodetectionfrm.h (revision 0) @@ -0,0 +1,69 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef AUTODETECTIONFRM_H +#define AUTODETECTIONFRM_H + +#include +#include "ui_autodetectionfrm.h" +#include "autodetection.h" + +struct DeviceGui +{ + QRadioButton* select; + QWidget* targets; + QWidget* mountpoints; + QPushButton* browse; + QLabel* state; +}; + +class AutodetectionFrm: public QDialog +{ + Q_OBJECT +public: + AutodetectionFrm(QDialog* parent); + + bool scan(); + QString selectedTarget() {return m_target;} + QString selectedMountpoint() {return m_mountpoint;} + +private slots: + //! accept current configuration values and close window + void accept(void); + //! close window and dont save configuration + void reject(void); + + +private: + Ui::AutodetectionFrm ui; + //! creates all dynamic window content + void setUpWindow(); + + QString m_target; + QString m_mountpoint; + QList m_deviceList; + + QList m_deviceGui; +}; + + +#endif + Index: rbutil/rbutilqt/autodetectionfrm.ui =================================================================== --- rbutil/rbutilqt/autodetectionfrm.ui (revision 0) +++ rbutil/rbutilqt/autodetectionfrm.ui (revision 0) @@ -0,0 +1,125 @@ + + + AutodetectionFrm + + + + 0 + 0 + 484 + 130 + + + + + 0 + 0 + + + + Autodetection + + + + + + + 0 + 0 + + + + Rockbox Utility has detected the following Devices: + + + + + + + Qt::Horizontal + + + + 306 + 20 + + + + + + + + 2 + + + + + &Ok + + + + :/icons/go-next.png:/icons/go-next.png + + + + + + + &Cancel + + + + :/icons/process-stop.png:/icons/process-stop.png + + + + + + + + + + 0 + 2 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 466 + 60 + + + + + 0 + 0 + + + + + + + + + + + + Index: rbutil/rbutilqt/base/autodetection.cpp =================================================================== --- rbutil/rbutilqt/base/autodetection.cpp (revision 22640) +++ rbutil/rbutilqt/base/autodetection.cpp (working copy) @@ -57,153 +57,368 @@ Autodetection::Autodetection(QObject* parent): QObject(parent) { + } -bool Autodetection::detect() +bool Autodetection::scan() { - m_device = ""; - m_mountpoint = ""; - m_errdev = ""; + m_devices.clear(); + + // this produces a list of potential Devices, entrys may have more then one potential target because of dublicate usb-ids. No mountpoints + scanUsbIds(); + + //this searches all potential mountpoints for hints of a target, if it finds something, updates the devicelist. + scanMountpoints(); + + // search list of devices and return detectionmethods if there are still things left todo + QStringList neededMethods = collectNeededMethods(); + for(int i=0;i< neededMethods.size();i++) + { + if(neededMethods[i] == "ajbrec") + { + detectAjbrec(); + } + else if((neededMethods[i] == "ipodpatcher")) + { + int n; + // try ipodpatcher + // initialize sector buffer. Needed. + ipod_sectorbuf = NULL; + ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE); + struct ipod_t ipod; + n = ipod_scan(&ipod); + + //TODO Handle more the one ipod + + if(n == 1) + { + qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname; + updateDevice(QStringList(ipod.targetname),resolveMountPoint(ipod.diskname)); + } + else + { + qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n; + } + free(ipod_sectorbuf); + ipod_sectorbuf = NULL; + } + else if((neededMethods[i] == "sansapatcher")) + { + // try sansapatcher + // initialize sector buffer. Needed. + sansa_sectorbuf = NULL; + sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE); + struct sansa_t sansa; + int n = sansa_scan(&sansa); + + //TODO Handle more the one sansa + + if(n == 1) + { + qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname; + updateDevice(QStringList(QString("sansa%1").arg(sansa.targetname)),resolveMountPoint(sansa.diskname)); + + } + else { + qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n; + } + free(sansa_sectorbuf); + sansa_sectorbuf = NULL; + } + } + + // update the state of the devices + for(int i=0; i < m_devices.size();i++) + { + if((m_devices[i].state != Device::Error) && (m_devices[i].mountpoints.size() != 1 + || m_devices[i].targets.size() != 1 )) + { + m_devices[i].state = Device::Warning; + } + //else + // m_devices[i].state = Device::Ok; + } + return true; +} - detectUsb(); +void Autodetection::detectAjbrec() +{ + for(int i=0; i < m_devices.size();i++) + { + if(m_devices[i].state != Device::Error && m_devices[i].methods.contains("ajbrec")) + { + for(int j=0; j < m_devices[i].mountpoints.size();j++) + { + QString mountpoint = m_devices[i].mountpoints[j]; + QString device = ""; + QFile f( mountpoint+ "/ajbrec.ajz"); + unsigned char header[24]; + f.open(QIODevice::ReadOnly); + if(!f.read((char*)header, 24)) continue; //continue to next mountpoint + // check the header of the file. + // recorder v1 had a 6 bytes sized header + // recorder v2, FM, Ondio SP and FM have a 24 bytes header. - // Try detection via rockbox.info / rbutil.log - QStringList mounts = mountpoints(); + // recorder v1 has the binary length in the first 4 bytes, so check + // for them first. + int len = (header[0]<<24) | (header[1]<<16) | (header[2]<<8) | header[3]; + if((f.size() - 6) == len) + { + device = "recorder"; + } + else + { + // size didn't match, now we need to assume we have a headerlength of 24. + switch(header[11]) { + case 2: + device = "recorderv2"; + break; + case 4: + device = "fmrecorder"; + break; + case 8: + device = "ondiofm"; + break; + case 16: + device = "ondiosp"; + break; + default: + break; + } + } + if(device != "") + { + updateDevice(QStringList(device),mountpoint); + qDebug() << "[Autodetect] ABJREC detected: "<< device << "at" << mountpoint; + f.close(); + break; //switch to next target + } + f.close(); + } + } + } +} + + +void Autodetection::scanUsbIds() +{ + // usbids holds the mapping in the form + // ((VID<<16)|(PID)), targetname + // the ini file needs to hold the IDs as hex values. + QMap usbids = RbSettings::usbIdMap(RbSettings::MapDevice); + QMap usberror = RbSettings::usbIdMap(RbSettings::MapError); + + // usb pid detection + QList attached; +#ifdef AUTODETECTION_TEST + QFile idsFile("usbids.txt"); + if (idsFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&idsFile); + while (!in.atEnd()) + { + attached.append(in.readLine().toInt(0, 16)); + } + } + else +#endif + attached = System::listUsbIds(); + // try every usb id + for(int i=0; i < attached.size(); i++) + { + if(usbids.contains(attached.at(i))) // found one or more targets with this usb-id + { + Device dev; + dev.usbid = attached.at(i); + dev.targets = usbids.values(attached.at(i)); + dev.state = Device::Ok; + m_devices.append(dev); + qDebug() << "[USB] detected supported player: " << dev.usbid << dev.targets; + } + else if(usberror.contains(attached.at(i))) // found one or more targets in wrong mode + { + Device dev; + dev.usbid = attached.at(i); + dev.targets = usberror.values(attached.at(i)); + dev.state = Device::Error; + dev.errstring = tr("This Device is in the wrong Mode"); + m_devices.append(dev); + qDebug() << "[USB] detected problem with player" << dev.usbid << dev.targets; + } + else //unknown usb-ids + { + // check if we know such a "unknown" device by name + QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0')); + if(!RbSettings::platformValue(idstring, RbSettings::CurName).toString().isEmpty()) + { + Device dev; + dev.usbid = attached.at(i); + dev.state = Device::Error; + dev.errstring = tr("This Device is not compatible with Rockbox"); + m_devices.append(dev); + qDebug() << "[USB] detected incompatible player" << dev.usbid; + } + } + } +} + +void Autodetection::scanMountpoints() +{ + QStringList mounts; +#ifdef AUTODETECTION_TEST + QFile mountsFile("mountpoints.txt"); + if (mountsFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&mountsFile); + while (!in.atEnd()) + { + mounts.append(in.readLine()); + } + } + else +#endif + mounts = mountpoints(); + qDebug() << "[Autodetect] paths to check:" << mounts; for(int i=0; i< mounts.size();i++) { // do the file checking QDir dir(mounts.at(i)); - qDebug() << "[Autodetect] paths to check:" << mounts; if(dir.exists()) { // check logfile first. - if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) { + if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) + { QSettings log(mounts.at(i) + "/.rockbox/rbutil.log", QSettings::IniFormat, this); - if(!log.value("platform").toString().isEmpty()) { - if(m_device.isEmpty()) - m_device = log.value("platform").toString(); - m_mountpoint = mounts.at(i); - qDebug() << "[Autodetect] rbutil.log detected:" << m_device << m_mountpoint; - return true; + if(!log.value("platform").toString().isEmpty()) + { + updateDevice(log.value("platform").toStringList(),mounts.at(i)); + qDebug() << "[Autodetect] rbutil.log detected:" << log.value("platform").toString() << mounts.at(i); } + continue; } - - // check rockbox-info.txt afterwards. + + //check rockbox info RockboxInfo info(mounts.at(i)); if(info.success()) { - if(m_device.isEmpty()) - { - m_device = info.target(); - } - m_mountpoint = mounts.at(i); + //map target from rockbox-info to rbutils internal targets + QMap targetMap = RbSettings::targetValueMap(RbSettings::CurConfigureModel); + updateDevice(targetMap.values(info.target()),mounts.at(i)); qDebug() << "[Autodetect] rockbox-info.txt detected:" - << m_device << m_mountpoint; - return true; + << targetMap.values(info.target()) << mounts.at(i); + continue; } - - // check for some specific files in root folder + + // get a map of files to check + QMap fileMap = RbSettings::targetValueMap(RbSettings::CurDetectionFiles); QDir root(mounts.at(i)); QStringList rootentries = root.entryList(QDir::Files); - if(rootentries.contains("archos.mod", Qt::CaseInsensitive)) + QStringList fileKeys = fileMap.uniqueKeys(); + for(int j=0; j < fileKeys.size(); j++) { - // archos.mod in root folder -> Archos Player - m_device = "player"; - m_mountpoint = mounts.at(i); - return true; - } - if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive)) - { - // ONDIOST.BIN in root -> Ondio FM - m_device = "ondiofm"; - m_mountpoint = mounts.at(i); - return true; - } - if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive)) - { - // ONDIOSP.BIN in root -> Ondio SP - m_device = "ondiosp"; - m_mountpoint = mounts.at(i); - return true; - } - if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive)) - { - qDebug() << "[Autodetect] ajbrec.ajz found. Trying detectAjbrec()"; - if(detectAjbrec(mounts.at(i))) { - m_mountpoint = mounts.at(i); - qDebug() << "[Autodetect]" << m_device; - return true; + if(rootentries.contains(fileKeys[j], Qt::CaseInsensitive)) + { + //update mountpoint of matching targets, and we do not trust the info . + updateDevice(fileMap.values(fileKeys[j]),mounts.at(i)); + qDebug() << "[Autodetect] filedetection detected:" + << fileMap.values(fileKeys[j]) << mounts.at(i); } - } + } + // detection based on player specific folders + QMap folderMap = RbSettings::targetValueMap(RbSettings::CurDetectionFolders); QStringList rootfolders = root.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); - if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive)) + QStringList folderKeys = folderMap.uniqueKeys(); + for(int j=0; j < folderKeys.size(); j++) { - // GBSYSTEM folder -> Gigabeat - m_device = "gigabeatf"; - m_mountpoint = mounts.at(i); - return true; + if(rootfolders.contains(folderKeys[j], Qt::CaseInsensitive)) + { + //update mountpoint of matching targets, and we do not trust the info . + updateDevice(folderMap.values(folderKeys[j]),mounts.at(i)); + qDebug() << "[Autodetect] folderdetection detected:" + << folderMap.values(folderKeys[j]) << mounts.at(i); + } } -#if defined(Q_OS_WIN32) - // on windows, try to detect the drive letter of an Ipod - if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive)) + } + } +} + +// this merges new target info into the device list, in a "clever" way +void Autodetection::updateDevice(QStringList target,QString mountpoint) +{ + // if the targetlist contains only one device, we assume the info is exact + bool exact = (target.size() == 1) ? true: false; + + for(int i=0;i Ipod found - // detecting of the Ipod type is done below using ipodpatcher - m_mountpoint = mounts.at(i); + if(m_devices[i].targets.contains(target[j])) + newTargetList.append(target[j]); } -#endif + + // find the target which has at least on entry in the newTargetList, ie a match + if(newTargetList.size() > 0) + { + // if the info is exact, and the current device contains more then one mountpoint, or it is the same mountpoint + if(exact && (m_devices[i].mountpoints.size() != 1 || m_devices[i].mountpoints == QStringList(mountpoint))) + { + // "claim" this mountpoint, and remove it from all other entrys + for(int j=0; j < m_devices.size(); j++) + { + m_devices[j].mountpoints.removeAll(mountpoint); + } + // replace current device info with the given info. + m_devices[i].mountpoints= QStringList(mountpoint); + m_devices[i].targets = newTargetList; + qDebug() << "[updateDevice] " << m_devices[i].targets << "at" << m_devices[i].mountpoints; + return; //end here + } + else // non-trustworthy info, just add the mountpoints + { + //add mountpoint if it isnt already there + if(!m_devices[i].mountpoints.contains(mountpoint)) + { + m_devices[i].mountpoints.append(mountpoint); + qDebug() << "[updateDevice] " << m_devices[i].targets << "at" << m_devices[i].mountpoints; + } + // continue with other devices + } + } } - } +} - int n; - // try ipodpatcher - // initialize sector buffer. Needed. - ipod_sectorbuf = NULL; - ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE); - struct ipod_t ipod; - n = ipod_scan(&ipod); - if(n == 1) { - qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname; - m_device = ipod.targetname; - m_mountpoint = resolveMountPoint(ipod.diskname); - return true; - } - else { - qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n; - } - free(ipod_sectorbuf); - ipod_sectorbuf = NULL; - // try sansapatcher - // initialize sector buffer. Needed. - sansa_sectorbuf = NULL; - sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE); - struct sansa_t sansa; - n = sansa_scan(&sansa); - if(n == 1) { - qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname; - m_device = QString("sansa%1").arg(sansa.targetname); - m_mountpoint = resolveMountPoint(sansa.diskname); - return true; +QStringList Autodetection::collectNeededMethods() +{ + QStringList methods; + for(int i=0;i usbids = RbSettings::usbIdMap(RbSettings::MapDevice); - QMap usberror = RbSettings::usbIdMap(RbSettings::MapError); - QMap usbincompat = RbSettings::usbIdMap(RbSettings::MapIncompatible); - - // usb pid detection - QList attached; - attached = System::listUsbIds(); - - int i = attached.size(); - while(i--) { - if(usbids.contains(attached.at(i))) { - m_device = usbids.value(attached.at(i)); - qDebug() << "[USB] detected supported player" << m_device; - return true; - } - if(usberror.contains(attached.at(i))) { - m_errdev = usberror.value(attached.at(i)); - qDebug() << "[USB] detected problem with player" << m_errdev; - return true; - } - QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0')); - if(!RbSettings::platformValue(idstring, RbSettings::CurName).toString().isEmpty()) { - m_incompat = idstring; - qDebug() << "[USB] detected incompatible player" << m_incompat; - return true; - } - } - return false; -} - - -bool Autodetection::detectAjbrec(QString root) -{ - QFile f(root + "/ajbrec.ajz"); - char header[24]; - f.open(QIODevice::ReadOnly); - if(!f.read(header, 24)) return false; - - // check the header of the file. - // recorder v1 had a 6 bytes sized header - // recorder v2, FM, Ondio SP and FM have a 24 bytes header. - - // recorder v1 has the binary length in the first 4 bytes, so check - // for them first. - int len = (header[0]<<24) | (header[1]<<16) | (header[2]<<8) | header[3]; - qDebug() << "[Autodetect] ABJREC possible bin length:" << len - << "file len:" << f.size(); - if((f.size() - 6) == len) - m_device = "recorder"; - - // size didn't match, now we need to assume we have a headerlength of 24. - switch(header[11]) { - case 2: - m_device = "recorderv2"; - break; - - case 4: - m_device = "fmrecorder"; - break; - - case 8: - m_device = "ondiofm"; - break; - - case 16: - m_device = "ondiosp"; - break; - - default: - break; - } - f.close(); - - if(m_device.isEmpty()) return false; - return true; -} - Index: rbutil/rbutilqt/base/autodetection.h =================================================================== --- rbutil/rbutilqt/base/autodetection.h (revision 22640) +++ rbutil/rbutilqt/base/autodetection.h (working copy) @@ -25,6 +25,26 @@ #include +#define AUTODETECTION_TEST + +struct Device +{ + enum DeviceStatus + { + Ok, + Warning, + Error + }; + + int usbid; + QStringList targets; + QStringList mountpoints; + QStringList methods; + DeviceStatus state; + QString errstring; +}; + + class Autodetection :public QObject { Q_OBJECT @@ -32,27 +52,20 @@ public: Autodetection(QObject* parent=0); - bool detect(); - - QString getDevice() {return m_device;} - QString getMountPoint() {return m_mountpoint;} - QString errdev(void) { return m_errdev; } - QString incompatdev(void) { return m_incompat; } + bool scan(); + + QList getDevices() {return m_devices;} static QStringList mountpoints(void); static QString resolveDevicename(QString path); - private: - QString resolveMountPoint(QString); - bool detectUsb(void); - bool detectAjbrec(QString); - - QString m_device; - QString m_mountpoint; - QString m_errdev; - QString m_incompat; - QList m_usbconid; + void scanUsbIds(); + void scanMountpoints(); + void updateDevice(QStringList target,QString mountpoint); + QStringList collectNeededMethods(); + QString resolveMountPoint(QString device); + void detectAjbrec(); + QList m_devices; }; #endif /*AUTODETECTION_H_*/ - Index: rbutil/rbutilqt/base/rbsettings.cpp =================================================================== --- rbutil/rbutilqt/base/rbsettings.cpp (revision 22640) +++ rbutil/rbutilqt/base/rbsettings.cpp (working copy) @@ -55,6 +55,9 @@ { RbSettings::CurName, ":platform:/name", "" }, { RbSettings::CurBuildserverModel, ":platform:/buildserver_modelname", "" }, { RbSettings::CurConfigureModel, ":platform:/configure_modelname", "" }, + { RbSettings::CurDetectionFiles, ":platform:/detectionfiles","" }, + { RbSettings::CurDetectionFolders, ":platform:/detectionfolders","" }, + { RbSettings::CurDetectionMethod, ":platform:/detectionmethod","" }, }; // user settings @@ -313,7 +316,7 @@ QStringList ids = systemSettings->value(t).toStringList(); int j = ids.size(); while(j--) - map.insert(ids.at(j).toInt(0, 16), target); + map.insertMulti(ids.at(j).toInt(0, 16), target); systemSettings->endGroup(); } @@ -321,6 +324,44 @@ } +QMap RbSettings::targetValueMap(enum SystemSettings setting) +{ + ensureRbSettingsExists(); + + QMap map; + QStringList platforms; + systemSettings->beginGroup("platforms"); + platforms = systemSettings->childKeys(); + systemSettings->endGroup(); + + // locate setting item + int i = 0; + while(SystemSettingsList[i].setting != setting) + i++; + + for(int j = 0; j < platforms.size(); j++) + { + systemSettings->beginGroup("platforms"); + QString target = systemSettings->value(platforms.at(j)).toString(); + systemSettings->endGroup(); + + QString key = SystemSettingsList[i].name; + QString dev = SystemSettingsList[i].def; + + key.replace(":platform:", target); + dev.replace(":platform:", target); + + QStringList values = systemSettings->value(key,dev).toStringList(); + int k = values.size(); + while(k--) + map.insertMulti(values.at(k), target); + } + + return map; +} + + + QString RbSettings::constructSettingPath(QString path, QString substitute) { QString platform = userSettings->value("platform").toString(); Index: rbutil/rbutilqt/base/rbsettings.h =================================================================== --- rbutil/rbutilqt/base/rbsettings.h (revision 22640) +++ rbutil/rbutilqt/base/rbsettings.h (working copy) @@ -94,6 +94,9 @@ CurName, CurBuildserverModel, CurConfigureModel, + CurDetectionFiles, + CurDetectionFolders, + CurDetectionMethod, }; //! call this to flush the user Settings @@ -110,6 +113,8 @@ static QString brand(QString plattform); //! returns a map of usb-ids and their targets static QMap usbIdMap(enum MapType); + //! returns a map with the value and the correspondig target + static QMap targetValueMap(enum SystemSettings setting); //! get a value from system settings static QVariant value(enum SystemSettings setting); //! get a value from user settings Index: rbutil/rbutilqt/configure.cpp =================================================================== --- rbutil/rbutilqt/configure.cpp (revision 22640) +++ rbutil/rbutilqt/configure.cpp (working copy) @@ -22,6 +22,7 @@ #include "version.h" #include "configure.h" #include "autodetection.h" +#include "autodetectionfrm.h" #include "ui_configurefrm.h" #include "browsedirtree.h" #include "encoders.h" @@ -535,16 +536,17 @@ void Config::autodetect() { - Autodetection detector(this); - // disable tree during detection as "working" feedback. - // TODO: replace the tree view with a splash screen during this time. - ui.treeDevices->setEnabled(false); - this->setCursor(Qt::WaitCursor); - QCoreApplication::processEvents(); - - if(detector.detect()) //let it detect + AutodetectionFrm detectionFrm(this); + if(detectionFrm.scan()) { - QString devicename = detector.getDevice(); + + // disable tree during detection as "working" feedback. + // TODO: replace the tree view with a splash screen during this time. + ui.treeDevices->setEnabled(false); + this->setCursor(Qt::WaitCursor); + QCoreApplication::processEvents(); + + QString devicename = detectionFrm.selectedTarget(); // deexpand all items for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++) ui.treeDevices->topLevelItem(a)->setExpanded(false); @@ -573,53 +575,29 @@ } this->unsetCursor(); - if(!detector.errdev().isEmpty()) { - QString text; - if(detector.errdev() == "sansae200") - text = tr("Sansa e200 in MTP mode found!\n" - "You need to change your player to MSC mode for installation. "); - if(detector.errdev() == "h10") - text = tr("H10 20GB in MTP mode found!\n" - "You need to change your player to UMS mode for installation. "); - text += tr("Unless you changed 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(RbSettings::platformValue(detector.incompatdev(), - RbSettings::CurName).toString()); - - QMessageBox::critical(this, tr("Fatal: player incompatible"), - text, QMessageBox::Ok); - return; - } - - if(detector.getMountPoint() != "" ) + if(detectionFrm.selectedMountpoint() != "" ) { - ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint())); + ui.mountPoint->setText(QDir::toNativeSeparators(detectionFrm.selectedMountpoint())); } else { QMessageBox::warning(this, tr("Autodetection"), - tr("Could not detect a Mountpoint.\n" - "Select your Mountpoint manually."), - QMessageBox::Ok ,QMessageBox::Ok); + tr("Could not detect a Mountpoint.\n" + "Select your Mountpoint manually."), + QMessageBox::Ok ,QMessageBox::Ok); } + + ui.treeDevices->setEnabled(true); } 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); + tr("Could not detect a device.\n" + "Select your device and Mountpoint manually."), + QMessageBox::Ok ,QMessageBox::Ok); - } - ui.treeDevices->setEnabled(true); + this->unsetCursor(); + } } Index: rbutil/rbutilqt/rbutil.ini =================================================================== --- rbutil/rbutilqt/rbutil.ini (revision 22640) +++ rbutil/rbutilqt/rbutil.ini (working copy) @@ -67,6 +67,10 @@ brand=Archos configure_modelname=player encoder=lame +detectionfiles=archos.mod +detectionfolders= +detectionmethod= +usbid=0x05ab0031 [recorder] name="Jukebox Recorder 6 / 10 / 15 / 20" @@ -77,6 +81,10 @@ brand=Archos configure_modelname=recorder encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x05ab0031, 0x05ab0060 [recorder8mb] name="Jukebox Recorder 6 / 10 / 15 / 20 (with 8MiB memory)" @@ -87,6 +95,10 @@ brand=Archos configure_modelname=recorder encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x05ab0031, 0x05ab0060 [recorderv2] name="Jukebox Recorder v2 (20GB)" @@ -97,6 +109,10 @@ brand=Archos configure_modelname=recorderv2 encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x05ab0060 [fmrecorder] name="Jukebox Recorder FM" @@ -107,6 +123,10 @@ brand=Archos configure_modelname=fmrecorder encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x05ab0060 [fmrecorder8mb] name="Jukebox Recorder FM (with 8MiB memory)" @@ -117,6 +137,10 @@ brand=Archos configure_modelname=fmrecorder encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x05ab0060 [ondiosp] name="Ondio SP" @@ -127,6 +151,10 @@ brand=Archos configure_modelname=ondiosp encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x058f9330 [ondiofm] name="Ondio FM" @@ -137,6 +165,10 @@ brand=Archos configure_modelname=ondiofm encoder=lame +detectionfiles=ajbrec.ajz +detectionfolders= +detectionmethod=ajbrec +usbid=0x058f9330 [h100] name="iHP100 / iHP110" @@ -149,6 +181,9 @@ usbid=0x10063001 configure_modelname=h100 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [h120] name="iHP120 / iHP140 / H120 / H140" @@ -161,6 +196,9 @@ usbid=0x10063002 configure_modelname=h120 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [h300] name="H320 / H340" @@ -173,6 +211,9 @@ usbid=0x10063003 configure_modelname=h300 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [h10_5gbums] name="H10 (5 / 6GB) UMS" @@ -185,6 +226,9 @@ usbid=0x41022002 configure_modelname=h10_5gb encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [h10_5gbmtp] name="H10 (5 / 6GB) MTP" @@ -197,6 +241,9 @@ usbid=0x41022105 configure_modelname=h10_5gb encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [h10] name="H10 (20GB)" @@ -210,6 +257,9 @@ usberror=0x41022101 configure_modelname=h10 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [ipod1g2g] name="Ipod (1st / 2nd gen)" @@ -220,6 +270,10 @@ brand=Apple configure_modelname=ipod1g2g encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid= [ipodcolor] name="Ipod Color / Photo / U2 (4th gen)" @@ -230,6 +284,10 @@ brand=Apple configure_modelname=ipodcolor encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1204 [ipodnano] name="Ipod Nano (1st gen)" @@ -240,6 +298,10 @@ brand=Apple configure_modelname=ipodnano encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac120a [ipod4gray] name="Ipod (4th gen, greyscale)" @@ -250,6 +312,10 @@ brand=Apple configure_modelname=ipod4g encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1203 [ipodvideo] name="Ipod Video (5th gen) 30GB" @@ -260,6 +326,10 @@ brand=Apple configure_modelname=ipodvideo encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1209 [ipodvideo64mb] name="Ipod Video (5th gen) 60/80GB" @@ -270,6 +340,10 @@ brand=Apple configure_modelname=ipodvideo encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1209 [ipod3g] name="Ipod (3rd gen)" @@ -281,6 +355,10 @@ usbid=0x05ac1201 configure_modelname=ipod3g encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1201 [ipodmini1g] name="Ipod Mini (1st gen)" @@ -291,6 +369,10 @@ brand=Apple configure_modelname=ipodmini encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1205 [ipodmini2g] name="Ipod Mini (2nd gen)" @@ -301,6 +383,10 @@ brand=Apple configure_modelname=ipodmini2g encoder=rbspeex +detectionfiles= +detectionfolders=iPod_Control +detectionmethod=ipodpatcher +usbid=0x05ac1205 [iaudiox5] name="iAudio X5 / X5L" @@ -313,6 +399,9 @@ usbid=0x0e210510, 0x0e210513 configure_modelname=x5 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [iaudiox5v] name="iAudio X5V" @@ -324,6 +413,10 @@ brand=Cowon configure_modelname=x5 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= +usbid=0x0e210510, 0x0e210513 [iaudiom5] name="iAudio M5 / M5L" @@ -336,6 +429,9 @@ usbid=0x0e210520 configure_modelname=m5 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [iaudiom3] name="iAudio M3 / M3L" @@ -348,6 +444,9 @@ usbid=0x0e210500 configure_modelname=m3 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [gigabeatf] name="Gigabeat F / X" @@ -360,6 +459,9 @@ usbid=0x09300009 configure_modelname=gigabeatf encoder=rbspeex +detectionfiles= +detectionfolders=GBSYSTEM +detectionmethod= [sansae200] name="Sansa e200v1 series" @@ -372,6 +474,9 @@ usberror=0x07810720 configure_modelname=e200 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod=sansapatcher [sansac200] name="Sansa c200v1 series" @@ -383,6 +488,9 @@ usbid=0x07817450, 0x07817451 configure_modelname=c200 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod=sansapatcher [sansae200v2] name="Sansa e200v2 series" @@ -396,6 +504,9 @@ usberror=0x07817422 configure_modelname=e200v2 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [sansafuze] name="Sansa Fuze" @@ -409,6 +520,9 @@ usberror=0x078174c0 configure_modelname=fuze encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [sansam200v4] name="Sansa m200v4" @@ -418,10 +532,13 @@ bootloaderfile=/m200a.bin manualname= brand=Sandisk -usbid= -usberror= +usbid=0x07817431 +usberror=0x07817430 configure_modelname=m200v4 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [sansaclip] name="Sansa Clip" @@ -435,6 +552,9 @@ usberror=0x07817432 configure_modelname=clip encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [mrobe100] name="m:robe100" @@ -447,6 +567,9 @@ usbid=0x07b40280 configure_modelname=mrobe100 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [ondavx747] name="VX747" @@ -459,6 +582,9 @@ usbid=0x07c4a4a5 configure_modelname=ondavx747 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [ondavx747p] name="VX747+" @@ -471,6 +597,9 @@ usbid=0x07c4a4a5 configure_modelname=ondavx747p encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [ondavx777] name="VX777" @@ -483,6 +612,9 @@ usbid=0x07c4a4a5 configure_modelname=ondavx777 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [smsgyh820] name="YH-820" @@ -495,6 +627,9 @@ usbid=0x04e85023 configure_modelname=yh820 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [smsgyh920] name="YH-920" @@ -507,6 +642,9 @@ usbid=0x04e85022, 0x04e8501d configure_modelname=yh920 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [smsgyh925] name="YH-925" @@ -519,6 +657,9 @@ usbid=0x04e85024 configure_modelname=yh925 encoder=rbspeex +detectionfiles= +detectionfolders= +detectionmethod= [05ac1260] name="Apple Ipod Nano (Second Generation)" Index: rbutil/rbutilqt/rbutilqt.pro =================================================================== --- rbutil/rbutilqt/rbutilqt.pro (revision 22640) +++ rbutil/rbutilqt/rbutilqt.pro (working copy) @@ -115,7 +115,8 @@ base/bootloaderinstallchinachip.cpp \ base/bootloaderinstallams.cpp \ ../../tools/mkboot.c \ - ../../tools/iriver.c + ../../tools/iriver.c \ + autodetectionfrm.cpp HEADERS += rbutilqt.h \ install.h \ @@ -172,7 +173,8 @@ base/bootloaderinstallchinachip.h \ base/bootloaderinstallams.h \ ../../tools/mkboot.h \ - ../../tools/iriver.h + ../../tools/iriver.h \ + autodetectionfrm.h # Needed by QT on Win INCLUDEPATH = $$_PRO_FILE_PWD_ $$_PRO_FILE_PWD_/irivertools $$_PRO_FILE_PWD_/zip $$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base @@ -207,7 +209,8 @@ previewfrm.ui \ createvoicefrm.ui \ sysinfofrm.ui \ - systracefrm.ui + systracefrm.ui \ + autodetectionfrm.ui RESOURCES += $$_PRO_FILE_PWD_/rbutilqt.qrc win32 {