summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-03-26 02:06:21 (UTC)
committer llornkcor <llornkcor>2003-03-26 02:06:21 (UTC)
commita76176911328349414203edda3785ac8925c0648 (patch) (unidiff)
tree30e345d6c458b3dc2f0fd06fe900d4b7203e902f
parentf50d60ad220bbaf76e6cbcb07caf5bed037311d5 (diff)
downloadopie-a76176911328349414203edda3785ac8925c0648.zip
opie-a76176911328349414203edda3785ac8925c0648.tar.gz
opie-a76176911328349414203edda3785ac8925c0648.tar.bz2
add static isCf, isSd, and isMmc
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp61
-rw-r--r--library/storage.h8
2 files changed, 65 insertions, 4 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index a7c466d..912b22d 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,17 +1,18 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org> 2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
3** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 4** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 5**
5** This file is part of Qtopia Environment. 6** This file is part of Opie Environment.
6** 7**
7** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 11** packaging of this file.
11** 12**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 15**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 17**
17** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
@@ -28,24 +29,28 @@
28#include <qtimer.h> 29#include <qtimer.h>
29#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
30 31
31#include <stdio.h> 32#include <stdio.h>
32 33
33#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 34#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
34#include <sys/vfs.h> 35#include <sys/vfs.h>
35#include <mntent.h> 36#include <mntent.h>
36#endif 37#endif
37 38
38#include <qstringlist.h> 39#include <qstringlist.h>
39 40
41#include <sys/vfs.h>
42#include <mntent.h>
43
44
40static bool isCF(const QString& m) 45static bool isCF(const QString& m)
41{ 46{
42 FILE* f = fopen("/var/run/stab", "r"); 47 FILE* f = fopen("/var/run/stab", "r");
43 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 48 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
44 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 49 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
45 if ( f ) { 50 if ( f ) {
46 char line[1024]; 51 char line[1024];
47 char devtype[80]; 52 char devtype[80];
48 char devname[80]; 53 char devname[80];
49 while ( fgets( line, 1024, f ) ) { 54 while ( fgets( line, 1024, f ) ) {
50 // 0 ide ide-cs 0 hda 3 0 55 // 0 ide ide-cs 0 hda 3 0
51 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 56 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
@@ -165,24 +170,78 @@ void StorageInfo::update()
165 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 170 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
166 mFileSystems.append( fs ); 171 mFileSystems.append( fs );
167 } 172 }
168 emit disksChanged(); 173 emit disksChanged();
169 } else { 174 } else {
170 // just update them 175 // just update them
171 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 176 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
172 i.current()->update(); 177 i.current()->update();
173 } 178 }
174#endif 179#endif
175} 180}
176 181
182bool deviceTab( const char *device) {
183 QString name = device;
184 bool hasDevice=false;
185 struct mntent *me;
186 FILE *mntfp = setmntent( "/etc/mtab", "r" );
187 if ( mntfp ) {
188 while ( (me = getmntent( mntfp )) != 0 ) {
189 QString deviceName = me->mnt_fsname;
190// qDebug(deviceName);
191 if( deviceName.left(name.length()) == name) {
192 hasDevice = true;
193 }
194 }
195 }
196 endmntent( mntfp );
197 return hasDevice;
198}
199
200/*!
201 * @fn hasCf()
202 * @brief returns whether device has Cf mounted
203 *
204 */
205bool StorageInfo::hasCf()
206{
207 return deviceTab("/dev/hd");
208}
209
210/*!
211 * @fn hasSd()
212 * @brief returns whether device has SD mounted
213 *
214 */
215bool StorageInfo::hasSd()
216{
217 return deviceTab("/dev/mmcd");
218}
219
220/*!
221 * @fn hasMmc()
222 * @brief reutrns whether device has mmc mounted
223 *
224 */
225bool StorageInfo::hasMmc()
226{
227 bool hasMmc=false;
228 if( deviceTab("/dev/mmc/part"))
229 hasMmc=true;
230 if( deviceTab("/dev/mmcd"))
231 hasMmc=true;
232 return hasMmc;
233}
234
235
177//--------------------------------------------------------------------------- 236//---------------------------------------------------------------------------
178 237
179FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) 238FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
180 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) 239 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
181{ 240{
182 update(); 241 update();
183} 242}
184 243
185void FileSystem::update() 244void FileSystem::update()
186{ 245{
187#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 246#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
188 struct statfs fs; 247 struct statfs fs;
diff --git a/library/storage.h b/library/storage.h
index 66a9f9d..0a0698f 100644
--- a/library/storage.h
+++ b/library/storage.h
@@ -23,27 +23,29 @@
23#include <qobject.h> 23#include <qobject.h>
24#include <qlist.h> 24#include <qlist.h>
25 25
26class FileSystem; 26class FileSystem;
27class QCopChannel; 27class QCopChannel;
28 28
29class StorageInfo : public QObject 29class StorageInfo : public QObject
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32public: 32public:
33 StorageInfo( QObject *parent=0 ); 33 StorageInfo( QObject *parent=0 );
34 34
35 const QList<FileSystem> &fileSystems() const { return mFileSystems; } 35 const QList<FileSystem> &fileSystems() const { return mFileSystems; }
36 const FileSystem *fileSystemOf( const QString &filename ); 36 const FileSystem *fileSystemOf( const QString &filename );
37 37 static bool hasCf();
38 static bool hasSd();
39 static bool hasMmc();
38signals: 40signals:
39 void disksChanged(); 41 void disksChanged();
40 42
41public slots: 43public slots:
42 void update(); 44 void update();
43 45
44private slots: 46private slots:
45 void cardMessage( const QCString& msg, const QByteArray& data ); 47 void cardMessage( const QCString& msg, const QByteArray& data );
46private: 48private:
47 QList<FileSystem> mFileSystems; 49 QList<FileSystem> mFileSystems;
48 QCopChannel *channel; 50 QCopChannel *channel;
49}; 51};