1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: autodetection.cpp 14027 2007-07-27 17:42:49Z domonoky $
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "autodetection.h"
22 Autodetection::Autodetection(QObject
* parent
): QObject(parent
)
27 bool Autodetection::detect()
32 // Try detection via rockbox.info
33 QStringList mountpoints
= getMountpoints();
35 for(int i
=0; i
< mountpoints
.size();i
++)
37 QDir
dir(mountpoints
.at(i
));
40 QFile
file(mountpoints
.at(i
) + "/.rockbox/rockbox-info.txt");
43 file
.open(QIODevice::ReadOnly
| QIODevice::Text
);
44 QString line
= file
.readLine();
45 if(line
.startsWith("Target: "))
47 line
.remove("Target: ");
49 m_mountpoint
= mountpoints
.at(i
);
59 int n
= ipod_scan(&ipod
);
61 qDebug() << "Ipod found:" << ipod
.modelstr
<< "at" << ipod
.diskname
;
62 m_device
= ipod
.targetname
;
63 m_mountpoint
= resolveMountPoint(ipod
.diskname
);
74 QStringList
Autodetection::getMountpoints()
76 #if defined(Q_OS_WIN32)
78 QFileInfoList list
= QDir::drives();
79 for(int i
=0; i
<list
.size();i
++)
81 tempList
<< list
.at(i
).absolutePath();
85 #elif defined(Q_OS_MACX)
87 return dir
.entryList();
88 #elif defined(Q_OS_LINUX)
91 FILE *fp
= fopen( "/proc/mounts", "r" );
92 if( !fp
) return tempList
;
94 while( fscanf( fp
, "%as %as %*s %*s %*s %*s", &dev
, &dir
) != EOF
)
104 #error Unknown Plattform
108 QString
Autodetection::resolveMountPoint(QString device
)
110 qDebug() << "Autodetection::resolveMountPoint(QString)" << device
;
111 #if defined(Q_OS_LINUX)
112 FILE *fp
= fopen( "/proc/mounts", "r" );
113 if( !fp
) return QString("");
115 while( fscanf( fp
, "%as %as %*s %*s %*s %*s", &dev
, &dir
) != EOF
)
117 if( QString(dev
).startsWith(device
) )
119 QString directory
= dir
;