summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2007-08-05 19:48:04 +0000
committerDominik Wenger <domonoky@googlemail.com>2007-08-05 19:48:04 +0000
commit421411b73adadf17a23227cbb488677b937390e1 (patch)
tree067045c9afaf69c00e9bd6fae88148c984aa9857 /rbutil/rbutilqt
parentb3113674819cd8daf44750d129c5d8298e830df0 (diff)
downloadrockbox-421411b73adadf17a23227cbb488677b937390e1.tar.gz
rockbox-421411b73adadf17a23227cbb488677b937390e1.zip
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
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/autodetection.cpp99
-rw-r--r--rbutil/rbutilqt/autodetection.h47
-rw-r--r--rbutil/rbutilqt/configure.cpp60
-rw-r--r--rbutil/rbutilqt/configure.h1
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro2
5 files changed, 207 insertions, 2 deletions
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: autodetection.cpp 14027 2007-07-27 17:42:49Z domonoky $
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "autodetection.h"
21
22Autodetection::Autodetection(QObject* parent): QObject(parent)
23{
24
25}
26
27bool Autodetection::detect()
28{
29 m_device = "";
30 m_mountpoint = "";
31
32 // Try detection via rockbox.info
33 QStringList mountpoints = getMountpoints();
34
35 for(int i=0; i< mountpoints.size();i++)
36 {
37 QDir dir(mountpoints.at(i));
38 if(dir.exists())
39 {
40 QFile file(mountpoints.at(i) + "/.rockbox/rockbox-info.txt");
41 if(file.exists())
42 {
43 file.open(QIODevice::ReadOnly | QIODevice::Text);
44 QString line = file.readLine();
45 if(line.startsWith("Target: "))
46 {
47 line.remove("Target: ");
48 m_device = line;
49 m_mountpoint = mountpoints.at(i);
50 return true;
51 }
52 }
53 }
54 }
55
56 //try ipodpatcher
57
58
59 //try sansapatcher
60
61 return false;
62}
63
64
65QStringList Autodetection::getMountpoints()
66{
67#ifdef Q_OS_WIN32
68 QStringList tempList;
69 QFileInfoList list = QDir::drives();
70 for(int i=0; i<list.size();i++)
71 {
72 tempList << list.at(i).absolutePath();
73 }
74 return tempList;
75
76#elif Q_OS_MACX
77 QDir dir("/Volumes");
78 return dir.entryList();
79#elif Q_OS_LINUX
80 QStringList tempList;
81
82 FILE *fp = fopen( "/proc/mounts", "r" );
83 if( !fp ) return tempList;
84 char *dev, *dir;
85 while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
86 {
87 tempList << dir;
88 free( dev );
89 free( dir );
90 }
91 fclose( fp );
92
93 return tempList;
94#else
95#error Unknown Plattform
96#endif
97}
98
99
diff --git a/rbutil/rbutilqt/autodetection.h b/rbutil/rbutilqt/autodetection.h
new file mode 100644
index 0000000000..0a941a0d5d
--- /dev/null
+++ b/rbutil/rbutilqt/autodetection.h
@@ -0,0 +1,47 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: autodetection.h 14027 2007-07-27 17:42:49Z domonoky $
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20
21#ifndef AUTODETECTION_H_
22#define AUTODETECTION_H_
23
24#include <QtGui>
25
26class Autodetection :public QObject
27{
28 Q_OBJECT
29
30public:
31 Autodetection(QObject* parent=0);
32
33 bool detect();
34
35 QString getDevice() {return m_device;}
36 QString getMountPoint() {return m_mountpoint;}
37
38private:
39 QStringList getMountpoints();
40
41 QString m_device;
42 QString m_mountpoint;
43
44};
45
46
47#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 @@
20#include <QtGui> 20#include <QtGui>
21 21
22#include "configure.h" 22#include "configure.h"
23#include "autodetection.h"
23#include "ui_configurefrm.h" 24#include "ui_configurefrm.h"
24 25
25#ifdef __linux 26#ifdef __linux
@@ -61,17 +62,19 @@ Config::Config(QWidget *parent) : QDialog(parent)
61 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool))); 62 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
62 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool))); 63 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
63 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder())); 64 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
64 65 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
66
65 // disable unimplemented stuff 67 // disable unimplemented stuff
66 ui.buttonCacheBrowse->setEnabled(false); 68 ui.buttonCacheBrowse->setEnabled(false);
67 ui.cacheDisable->setEnabled(false); 69 ui.cacheDisable->setEnabled(false);
68 ui.cacheOfflineMode->setEnabled(false); 70 ui.cacheOfflineMode->setEnabled(false);
69 ui.buttonCacheClear->setEnabled(false); 71 ui.buttonCacheClear->setEnabled(false);
70 72
71 ui.buttonAutodetect->setEnabled(false); 73 //ui.buttonAutodetect->setEnabled(false);
72} 74}
73 75
74 76
77
75void Config::accept() 78void Config::accept()
76{ 79{
77 qDebug() << "Config::accept()"; 80 qDebug() << "Config::accept()";
@@ -338,3 +341,56 @@ void Config::browseFolder()
338 userSettings->setValue("defaults/mountpoint", files.at(0)); 341 userSettings->setValue("defaults/mountpoint", files.at(0));
339 } 342 }
340} 343}
344
345void Config::autodetect()
346{
347 Autodetection detector(this);
348
349 if(detector.detect()) //let it detect
350 {
351 QString devicename = detector.getDevice();
352 //deexpand the platform
353 ui.treeDevices->selectedItems().at(0)->parent()->setExpanded(false);
354 //deselect the selected item
355 ui.treeDevices->selectedItems().at(0)->setSelected(false);
356
357 // find the new item
358 //enumerate al plattform items
359 QList<QTreeWidgetItem*> itmList= ui.treeDevices->findItems("*",Qt::MatchWildcard);
360 for(int i=0; i< itmList.size();i++)
361 {
362 //enumerate device items
363 for(int j=0;j < itmList.at(i)->childCount();j++)
364 {
365 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
366
367 if( devicename.contains(data)) //item found
368 {
369 itmList.at(i)->child(j)->setSelected(true); //select the item
370 itmList.at(i)->setExpanded(true); //expand the platform item
371 break;
372 }
373 }
374 }
375
376 if(detector.getMountPoint() != "" )
377 {
378 ui.mountPoint->setText(detector.getMountPoint());
379 }
380 else
381 {
382 QMessageBox::warning(this, tr("Autodetection"),
383 tr("Could not detect a Mountpoint.\n"
384 "Select your Mountpoint manually."),
385 QMessageBox::Ok ,QMessageBox::Ok);
386 }
387 }
388 else
389 {
390 QMessageBox::warning(this, tr("Autodetection"),
391 tr("Could not detect a device.\n"
392 "Select your device and Mountpoint manually."),
393 QMessageBox::Ok ,QMessageBox::Ok);
394
395 }
396}
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
54 void setSystemProxy(bool); 54 void setSystemProxy(bool);
55 void updateLanguage(void); 55 void updateLanguage(void);
56 void browseFolder(void); 56 void browseFolder(void);
57 void autodetect(void);
57}; 58};
58 59
59#endif 60#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 \
11 progressloggergui.cpp \ 11 progressloggergui.cpp \
12 installtalkwindow.cpp \ 12 installtalkwindow.cpp \
13 talkfile.cpp \ 13 talkfile.cpp \
14 autodetection.cpp \
14 ../ipodpatcher/ipodpatcher.c \ 15 ../ipodpatcher/ipodpatcher.c \
15 ../sansapatcher/sansapatcher.c \ 16 ../sansapatcher/sansapatcher.c \
16 irivertools/irivertools.cpp \ 17 irivertools/irivertools.cpp \
@@ -33,6 +34,7 @@ HEADERS += rbutilqt.h \
33 installbl.h \ 34 installbl.h \
34 installtalkwindow.h \ 35 installtalkwindow.h \
35 talkfile.h \ 36 talkfile.h \
37 autodetection.h \
36 progressloggerinterface.h \ 38 progressloggerinterface.h \
37 progressloggergui.h \ 39 progressloggergui.h \
38 ../ipodpatcher/ipodpatcher.h \ 40 ../ipodpatcher/ipodpatcher.h \