mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
rbutilqt: initial port of the autodetection. (use only rockbox-info.txt at the moment)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14199 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b311367481
commit
421411b73a
5 changed files with 207 additions and 2 deletions
99
rbutil/rbutilqt/autodetection.cpp
Normal file
99
rbutil/rbutilqt/autodetection.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 by Dominik Wenger
|
||||||
|
* $Id: autodetection.cpp 14027 2007-07-27 17:42:49Z domonoky $
|
||||||
|
*
|
||||||
|
* All files in this archive are subject to the GNU General Public License.
|
||||||
|
* See the file COPYING in the source tree root for full license agreement.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "autodetection.h"
|
||||||
|
|
||||||
|
Autodetection::Autodetection(QObject* parent): QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Autodetection::detect()
|
||||||
|
{
|
||||||
|
m_device = "";
|
||||||
|
m_mountpoint = "";
|
||||||
|
|
||||||
|
// Try detection via rockbox.info
|
||||||
|
QStringList mountpoints = getMountpoints();
|
||||||
|
|
||||||
|
for(int i=0; i< mountpoints.size();i++)
|
||||||
|
{
|
||||||
|
QDir dir(mountpoints.at(i));
|
||||||
|
if(dir.exists())
|
||||||
|
{
|
||||||
|
QFile file(mountpoints.at(i) + "/.rockbox/rockbox-info.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
|
QString line = file.readLine();
|
||||||
|
if(line.startsWith("Target: "))
|
||||||
|
{
|
||||||
|
line.remove("Target: ");
|
||||||
|
m_device = line;
|
||||||
|
m_mountpoint = mountpoints.at(i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//try ipodpatcher
|
||||||
|
|
||||||
|
|
||||||
|
//try sansapatcher
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList Autodetection::getMountpoints()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
QStringList tempList;
|
||||||
|
QFileInfoList list = QDir::drives();
|
||||||
|
for(int i=0; i<list.size();i++)
|
||||||
|
{
|
||||||
|
tempList << list.at(i).absolutePath();
|
||||||
|
}
|
||||||
|
return tempList;
|
||||||
|
|
||||||
|
#elif Q_OS_MACX
|
||||||
|
QDir dir("/Volumes");
|
||||||
|
return dir.entryList();
|
||||||
|
#elif Q_OS_LINUX
|
||||||
|
QStringList tempList;
|
||||||
|
|
||||||
|
FILE *fp = fopen( "/proc/mounts", "r" );
|
||||||
|
if( !fp ) return tempList;
|
||||||
|
char *dev, *dir;
|
||||||
|
while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
|
||||||
|
{
|
||||||
|
tempList << dir;
|
||||||
|
free( dev );
|
||||||
|
free( dir );
|
||||||
|
}
|
||||||
|
fclose( fp );
|
||||||
|
|
||||||
|
return tempList;
|
||||||
|
#else
|
||||||
|
#error Unknown Plattform
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
47
rbutil/rbutilqt/autodetection.h
Normal file
47
rbutil/rbutilqt/autodetection.h
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 by Dominik Wenger
|
||||||
|
* $Id: autodetection.h 14027 2007-07-27 17:42:49Z domonoky $
|
||||||
|
*
|
||||||
|
* All files in this archive are subject to the GNU General Public License.
|
||||||
|
* See the file COPYING in the source tree root for full license agreement.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef AUTODETECTION_H_
|
||||||
|
#define AUTODETECTION_H_
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
class Autodetection :public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Autodetection(QObject* parent=0);
|
||||||
|
|
||||||
|
bool detect();
|
||||||
|
|
||||||
|
QString getDevice() {return m_device;}
|
||||||
|
QString getMountPoint() {return m_mountpoint;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList getMountpoints();
|
||||||
|
|
||||||
|
QString m_device;
|
||||||
|
QString m_mountpoint;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*AUTODETECTION_H_*/
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
#include "configure.h"
|
#include "configure.h"
|
||||||
|
#include "autodetection.h"
|
||||||
#include "ui_configurefrm.h"
|
#include "ui_configurefrm.h"
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
|
|
@ -61,17 +62,19 @@ Config::Config(QWidget *parent) : QDialog(parent)
|
||||||
connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
|
connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
|
||||||
connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
|
connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
|
||||||
connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
|
connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
|
||||||
|
connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
|
||||||
|
|
||||||
// disable unimplemented stuff
|
// disable unimplemented stuff
|
||||||
ui.buttonCacheBrowse->setEnabled(false);
|
ui.buttonCacheBrowse->setEnabled(false);
|
||||||
ui.cacheDisable->setEnabled(false);
|
ui.cacheDisable->setEnabled(false);
|
||||||
ui.cacheOfflineMode->setEnabled(false);
|
ui.cacheOfflineMode->setEnabled(false);
|
||||||
ui.buttonCacheClear->setEnabled(false);
|
ui.buttonCacheClear->setEnabled(false);
|
||||||
|
|
||||||
ui.buttonAutodetect->setEnabled(false);
|
//ui.buttonAutodetect->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Config::accept()
|
void Config::accept()
|
||||||
{
|
{
|
||||||
qDebug() << "Config::accept()";
|
qDebug() << "Config::accept()";
|
||||||
|
|
@ -338,3 +341,56 @@ void Config::browseFolder()
|
||||||
userSettings->setValue("defaults/mountpoint", files.at(0));
|
userSettings->setValue("defaults/mountpoint", files.at(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::autodetect()
|
||||||
|
{
|
||||||
|
Autodetection detector(this);
|
||||||
|
|
||||||
|
if(detector.detect()) //let it detect
|
||||||
|
{
|
||||||
|
QString devicename = detector.getDevice();
|
||||||
|
//deexpand the platform
|
||||||
|
ui.treeDevices->selectedItems().at(0)->parent()->setExpanded(false);
|
||||||
|
//deselect the selected item
|
||||||
|
ui.treeDevices->selectedItems().at(0)->setSelected(false);
|
||||||
|
|
||||||
|
// find the new item
|
||||||
|
//enumerate al plattform 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();
|
||||||
|
|
||||||
|
if( devicename.contains(data)) //item found
|
||||||
|
{
|
||||||
|
itmList.at(i)->child(j)->setSelected(true); //select the item
|
||||||
|
itmList.at(i)->setExpanded(true); //expand the platform item
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(detector.getMountPoint() != "" )
|
||||||
|
{
|
||||||
|
ui.mountPoint->setText(detector.getMountPoint());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Autodetection"),
|
||||||
|
tr("Could not detect a Mountpoint.\n"
|
||||||
|
"Select your Mountpoint manually."),
|
||||||
|
QMessageBox::Ok ,QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Autodetection"),
|
||||||
|
tr("Could not detect a device.\n"
|
||||||
|
"Select your device and Mountpoint manually."),
|
||||||
|
QMessageBox::Ok ,QMessageBox::Ok);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ class Config : public QDialog
|
||||||
void setSystemProxy(bool);
|
void setSystemProxy(bool);
|
||||||
void updateLanguage(void);
|
void updateLanguage(void);
|
||||||
void browseFolder(void);
|
void browseFolder(void);
|
||||||
|
void autodetect(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ SOURCES += rbutilqt.cpp \
|
||||||
progressloggergui.cpp \
|
progressloggergui.cpp \
|
||||||
installtalkwindow.cpp \
|
installtalkwindow.cpp \
|
||||||
talkfile.cpp \
|
talkfile.cpp \
|
||||||
|
autodetection.cpp \
|
||||||
../ipodpatcher/ipodpatcher.c \
|
../ipodpatcher/ipodpatcher.c \
|
||||||
../sansapatcher/sansapatcher.c \
|
../sansapatcher/sansapatcher.c \
|
||||||
irivertools/irivertools.cpp \
|
irivertools/irivertools.cpp \
|
||||||
|
|
@ -33,6 +34,7 @@ HEADERS += rbutilqt.h \
|
||||||
installbl.h \
|
installbl.h \
|
||||||
installtalkwindow.h \
|
installtalkwindow.h \
|
||||||
talkfile.h \
|
talkfile.h \
|
||||||
|
autodetection.h \
|
||||||
progressloggerinterface.h \
|
progressloggerinterface.h \
|
||||||
progressloggergui.h \
|
progressloggergui.h \
|
||||||
../ipodpatcher/ipodpatcher.h \
|
../ipodpatcher/ipodpatcher.h \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue