From 421411b73adadf17a23227cbb488677b937390e1 Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Sun, 5 Aug 2007 19:48:04 +0000 Subject: 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 --- rbutil/rbutilqt/autodetection.cpp | 99 +++++++++++++++++++++++++++++++++++++++ rbutil/rbutilqt/autodetection.h | 47 +++++++++++++++++++ rbutil/rbutilqt/configure.cpp | 60 +++++++++++++++++++++++- rbutil/rbutilqt/configure.h | 1 + rbutil/rbutilqt/rbutilqt.pro | 2 + 5 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 rbutil/rbutilqt/autodetection.cpp create mode 100644 rbutil/rbutilqt/autodetection.h (limited to 'rbutil/rbutilqt') diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp new file mode 100644 index 0000000000..3f7814282d --- /dev/null +++ b/rbutil/rbutilqt/autodetection.cpp @@ -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 ) \___| < | \_\ ( <_> > < < + * 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 + +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_*/ diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp index 53d1acfe06..90afd03741 100644 --- a/rbutil/rbutilqt/configure.cpp +++ b/rbutil/rbutilqt/configure.cpp @@ -20,6 +20,7 @@ #include #include "configure.h" +#include "autodetection.h" #include "ui_configurefrm.h" #ifdef __linux @@ -61,17 +62,19 @@ Config::Config(QWidget *parent) : QDialog(parent) connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool))); connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool))); connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder())); - + connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect())); + // disable unimplemented stuff ui.buttonCacheBrowse->setEnabled(false); ui.cacheDisable->setEnabled(false); ui.cacheOfflineMode->setEnabled(false); ui.buttonCacheClear->setEnabled(false); - ui.buttonAutodetect->setEnabled(false); + //ui.buttonAutodetect->setEnabled(false); } + void Config::accept() { qDebug() << "Config::accept()"; @@ -338,3 +341,56 @@ void Config::browseFolder() 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 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); + + } +} diff --git a/rbutil/rbutilqt/configure.h b/rbutil/rbutilqt/configure.h index 54e76d0247..f1e6837c4b 100644 --- a/rbutil/rbutilqt/configure.h +++ b/rbutil/rbutilqt/configure.h @@ -54,6 +54,7 @@ class Config : public QDialog void setSystemProxy(bool); void updateLanguage(void); void browseFolder(void); + void autodetect(void); }; #endif diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 56d471df65..4835444f6d 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -11,6 +11,7 @@ SOURCES += rbutilqt.cpp \ progressloggergui.cpp \ installtalkwindow.cpp \ talkfile.cpp \ + autodetection.cpp \ ../ipodpatcher/ipodpatcher.c \ ../sansapatcher/sansapatcher.c \ irivertools/irivertools.cpp \ @@ -33,6 +34,7 @@ HEADERS += rbutilqt.h \ installbl.h \ installtalkwindow.h \ talkfile.h \ + autodetection.h \ progressloggerinterface.h \ progressloggergui.h \ ../ipodpatcher/ipodpatcher.h \ -- cgit v1.2.3