summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/storage.cpp178
1 files changed, 98 insertions, 80 deletions
diff --git a/noncore/settings/sysinfo/storage.cpp b/noncore/settings/sysinfo/storage.cpp
index 4e81170..0a07a3b 100644
--- a/noncore/settings/sysinfo/storage.cpp
+++ b/noncore/settings/sysinfo/storage.cpp
@@ -16,21 +16,21 @@
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20// additions copyright 2002 by L.J. Potter
21#include <qlabel.h> 21#include <qlabel.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qlayout.h> 24#include <qlayout.h>
25#include "graph.h" 25#include "graph.h"
26#include "storage.h" 26#include "storage.h"
27 27
28#include <stdio.h> 28#include <stdio.h>
29#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 29 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
30#include <sys/vfs.h> 30#include <sys/vfs.h>
31#include <mntent.h> 31#include <mntent.h>
32#endif 32 #endif
33 33
34StorageInfo::StorageInfo( QWidget *parent, const char *name ) 34StorageInfo::StorageInfo( QWidget *parent, const char *name )
35 : QWidget( parent, name ) 35 : QWidget( parent, name )
36{ 36{
@@ -51,22 +51,21 @@ static bool isCF(const QString& m)
51 FILE* f = fopen("/var/run/stab", "r"); 51 FILE* f = fopen("/var/run/stab", "r");
52 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 52 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
53 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 53 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
54 if ( f ) { 54 if ( f ) {
55 char line[1024]; 55 char line[1024];
56 char devtype[80]; 56 char devtype[80];
57 char devname[80]; 57 char devname[80];
58 while ( fgets( line, 1024, f ) ) { 58 while ( fgets( line, 1024, f ) ) {
59 // 0 ide ide-cs 0 hda 3 0 59 // 0 ide ide-cs 0 hda 3 0
60 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 60 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) {
61 { 61 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
62 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 62 fclose(f);
63 fclose(f); 63 return TRUE;
64 return TRUE; 64 }
65 } 65 }
66 } 66 }
67 } 67 fclose(f);
68 fclose(f);
69 } 68 }
70 return FALSE; 69 return FALSE;
71} 70}
72 71
@@ -76,78 +75,91 @@ void StorageInfo::updateMounts()
76 struct mntent *me; 75 struct mntent *me;
77 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 76 FILE *mntfp = setmntent( "/etc/mtab", "r" );
78 QStringList curdisks; 77 QStringList curdisks;
79 QStringList curfs; 78 QStringList curfs;
79 QStringList mountList;
80 QStringList fsT;
80 bool rebuild = FALSE; 81 bool rebuild = FALSE;
81 int n=0; 82 int n=0;
82 if ( mntfp ) { 83 if ( mntfp ) {
83 while ( (me = getmntent( mntfp )) != 0 ) { 84 while ( (me = getmntent( mntfp )) != 0 ) {
84 QString fs = me->mnt_fsname; 85 QString fs = me->mnt_fsname;
85 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 86 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
86 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" ) 87 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
87 { 88 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs") {
88 n++; 89 n++;
89 curdisks.append(fs); 90 curdisks.append(fs);
90 QString d = me->mnt_dir; 91 QString d = me->mnt_dir;
91 curfs.append(d); 92 curfs.append(d);
92 if ( !disks.find(d) ) 93 QString mount = me->mnt_dir;
93 rebuild = TRUE; 94 mountList.append(mount);
94 } 95 QString t = me->mnt_type;
95 } 96 fsT.append(t);
96 endmntent( mntfp ); 97 if ( !disks.find(d) )
98 rebuild = TRUE;
99 }
100 }
101 endmntent( mntfp );
97 } 102 }
98 if ( rebuild || n != (int)disks.count() ) { 103 if ( rebuild || n != (int)disks.count() ) {
99 disks.clear(); 104 disks.clear();
100 lines.clear(); 105 lines.clear();
101 delete vb; 106 delete vb;
102 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 ); 107 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 );
103 bool frst=TRUE; 108 bool frst=TRUE;
104 QStringList::ConstIterator it=curdisks.begin(); 109 QStringList::ConstIterator it=curdisks.begin();
105 QStringList::ConstIterator fsit=curfs.begin(); 110 QStringList::ConstIterator fsit=curfs.begin();
106 for (; it!=curdisks.end(); ++it, ++fsit) { 111 QStringList::ConstIterator fsmount=mountList.begin();
107 if ( !frst ) { 112 QStringList::ConstIterator fsTit=fsT.begin();
108 QFrame *f = new QFrame( this ); 113
109 vb->addWidget(f); 114 for (; it!=curdisks.end(); ++it, ++fsit) {
110 f->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 115 if ( !frst ) {
111 lines.append(f); 116 QFrame *f = new QFrame( this );
112 f->show(); 117 vb->addWidget(f);
113 } frst=FALSE; 118 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
114 QString humanname=*it; 119 lines.append(f);
115 if ( isCF(humanname) ) 120 f->show();
116 humanname = tr("CF Card"); 121 } frst=FALSE;
117 else if ( humanname == "/dev/hda1" ) 122 QString humanname=*it;
118 humanname = tr("Hard Disk"); 123 if ( isCF(humanname) )
119 else if ( humanname.left(9) == "/dev/mmcd" ) 124 humanname = tr("CF Card: "+*fsmount+" "+*fsTit+" ");
120 humanname = tr("SD Card"); 125 else if ( humanname == "/dev/hda1" )
121 else if ( humanname.left(7) == "/dev/hd" ) 126 humanname = tr("Hard Disk "+*fsmount+" "+*fsTit+" ");
122 humanname = tr("Hard Disk") + " " + humanname.mid(7); 127 else if ( humanname.left(9) == "/dev/mmcd" )
123 else if ( humanname.left(7) == "/dev/sd" ) 128 humanname = tr("SD Card "+*fsmount+" "+*fsTit+" ");
124 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7); 129 else if ( humanname.left(7) == "/dev/hd" )
125 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 130 humanname = tr("Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" ";
126 humanname = tr("Internal Storage"); 131 else if ( humanname.left(7) == "/dev/sd" )
127 else if ( humanname.left(14) == "/dev/mtdblock/" ) 132 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" ";
128 humanname = tr("Internal Storage") + " " + humanname.mid(14); 133 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
129 else if ( humanname.left(13) == "/dev/mtdblock" ) 134 humanname = tr("Internal Storage "+*fsmount+" "+*fsTit+"\n");
130 humanname = tr("Internal Storage") + " " + humanname.mid(13); 135 else if ( humanname.left(14) == "/dev/mtdblock/" )
131 // etc. 136 humanname = tr("Internal Storage") + " " + humanname.mid(14)+" "+*fsmount+" "+*fsTit+" ";
132 MountInfo* mi = new MountInfo( *fsit, humanname, this ); 137 else if ( humanname.left(13) == "/dev/mtdblock" )
133 vb->addWidget(mi); 138 humanname = tr("Internal Storage") + " " + humanname.mid(13)+" "+*fsmount+" "+*fsTit+" ";
134 disks.insert(*fsit,mi); 139 else if ( humanname.left(9) == "/dev/root" )
135 mi->show(); 140 humanname = tr("Internal Storage "+*fsmount+" "+*fsTit+" ");
136 } 141 // etc.
137 vb->addStretch(); 142 MountInfo* mi = new MountInfo( *fsit, humanname, this );
143 vb->addWidget(mi);
144 disks.insert(*fsit,mi);
145 mi->show();
146 fsmount++;fsTit++;
147 }
148 vb->addStretch();
138 } else { 149 } else {
139 // just update them 150 // just update them
140 for (QDictIterator<MountInfo> i(disks); i.current(); ++i) 151 for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
141 i.current()->updateData(); 152 i.current()->updateData();
142 } 153 }
143#endif 154#endif
144} 155}
145 156
146 157
147MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name ) 158MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name )
148 : QWidget( parent, name ), title(ttl) 159 : QWidget( parent, name ), title(ttl)
149{ 160{
161 qDebug("new path is "+path);
150 fs = new FileSystem( path ); 162 fs = new FileSystem( path );
151 QVBoxLayout *vb = new QVBoxLayout( this, 3 ); 163 QVBoxLayout *vb = new QVBoxLayout( this, 3 );
152 164
153 totalSize = new QLabel( this ); 165 totalSize = new QLabel( this );
@@ -183,9 +195,9 @@ void MountInfo::updateData()
183 if ( !div ) div = 1; 195 if ( !div ) div = 1;
184 long total = fs->totalBlocks() * mult / div; 196 long total = fs->totalBlocks() * mult / div;
185 long avail = fs->availBlocks() * mult / div; 197 long avail = fs->availBlocks() * mult / div;
186 long used = total - avail; 198 long used = total - avail;
187 totalSize->setText( title + tr(" total: %1 kB").arg( total ) ); 199 totalSize->setText( title + tr("Total: %1 kB").arg( total ) );
188 data->clear(); 200 data->clear();
189 data->addItem( tr("Used (%1 kB)").arg(used), used ); 201 data->addItem( tr("Used (%1 kB)").arg(used), used );
190 data->addItem( tr("Available (%1 kB)").arg(avail), avail ); 202 data->addItem( tr("Available (%1 kB)").arg(avail), avail );
191 graph->repaint( FALSE ); 203 graph->repaint( FALSE );
@@ -206,15 +218,21 @@ void FileSystem::update()
206{ 218{
207#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 219#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
208 struct statfs fs; 220 struct statfs fs;
209 if ( !statfs( fspath.latin1(), &fs ) ) { 221 if ( !statfs( fspath.latin1(), &fs ) ) {
210 blkSize = fs.f_bsize; 222 if( fspath.left(8) == "/mnt/ram") { //ugly hack openzaurus
211 totalBlks = fs.f_blocks; 223 blkSize = fs.f_bsize;
212 availBlks = fs.f_bavail; 224 totalBlks = fs.f_blocks;
225 availBlks = fs.f_ffree;
226 } else {
227 blkSize = fs.f_bsize;
228 totalBlks = fs.f_blocks;
229 availBlks = fs.f_bavail;
230 }
213 } else { 231 } else {
214 blkSize = 0; 232 blkSize = 0;
215 totalBlks = 0; 233 totalBlks = 0;
216 availBlks = 0; 234 availBlks = 0;
217 } 235 }
218#endif 236#endif
219} 237}
220 238