summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/storage.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/noncore/settings/sysinfo/storage.cpp b/noncore/settings/sysinfo/storage.cpp
index 0a07a3b..f76fbdb 100644
--- a/noncore/settings/sysinfo/storage.cpp
+++ b/noncore/settings/sysinfo/storage.cpp
@@ -1,238 +1,240 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
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// additions copyright 2002 by L.J. Potter 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{
37 vb = 0; 37 vb = 0;
38 disks.setAutoDelete(TRUE); 38 disks.setAutoDelete(TRUE);
39 lines.setAutoDelete(TRUE); 39 lines.setAutoDelete(TRUE);
40 updateMounts(); 40 updateMounts();
41 startTimer( 5000 ); 41 startTimer( 5000 );
42} 42}
43 43
44void StorageInfo::timerEvent(QTimerEvent*) 44void StorageInfo::timerEvent(QTimerEvent*)
45{ 45{
46 updateMounts(); 46 updateMounts();
47} 47}
48 48
49static bool isCF(const QString& m) 49static bool isCF(const QString& m)
50{ 50{
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 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 61 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
62 fclose(f); 62 fclose(f);
63 return TRUE; 63 return TRUE;
64 } 64 }
65 } 65 }
66 } 66 }
67 fclose(f); 67 fclose(f);
68 } 68 }
69 return FALSE; 69 return FALSE;
70} 70}
71 71
72void StorageInfo::updateMounts() 72void StorageInfo::updateMounts()
73{ 73{
74#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 74#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
75 struct mntent *me; 75 struct mntent *me;
76 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 76 FILE *mntfp = setmntent( "/etc/mtab", "r" );
77 QStringList curdisks; 77 QStringList curdisks;
78 QStringList curfs; 78 QStringList curfs;
79 QStringList mountList; 79 QStringList mountList;
80 QStringList fsT; 80 QStringList fsT;
81 bool rebuild = FALSE; 81 bool rebuild = FALSE;
82 int n=0; 82 int n=0;
83 if ( mntfp ) { 83 if ( mntfp ) {
84 while ( (me = getmntent( mntfp )) != 0 ) { 84 while ( (me = getmntent( mntfp )) != 0 ) {
85 QString fs = me->mnt_fsname; 85 QString fs = me->mnt_fsname;
86 qDebug(fs+" "+(QString)me->mnt_type);
86 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 87 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
87 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 88 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
88 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs") { 89 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs") {
89 n++; 90 n++;
90 curdisks.append(fs); 91 curdisks.append(fs);
91 QString d = me->mnt_dir; 92 QString d = me->mnt_dir;
92 curfs.append(d); 93 curfs.append(d);
93 QString mount = me->mnt_dir; 94 QString mount = me->mnt_dir;
94 mountList.append(mount); 95 mountList.append(mount);
95 QString t = me->mnt_type; 96 QString t = me->mnt_type;
96 fsT.append(t); 97 fsT.append(t);
97 if ( !disks.find(d) ) 98 if ( !disks.find(d) )
98 rebuild = TRUE; 99 rebuild = TRUE;
99 } 100 }
100 } 101 }
101 endmntent( mntfp ); 102 endmntent( mntfp );
102 } 103 }
103 if ( rebuild || n != (int)disks.count() ) { 104 if ( rebuild || n != (int)disks.count() ) {
104 disks.clear(); 105 disks.clear();
105 lines.clear(); 106 lines.clear();
106 delete vb; 107 delete vb;
107 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 ); 108 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 );
108 bool frst=TRUE; 109 bool frst=TRUE;
109 QStringList::ConstIterator it=curdisks.begin(); 110 QStringList::ConstIterator it=curdisks.begin();
110 QStringList::ConstIterator fsit=curfs.begin(); 111 QStringList::ConstIterator fsit=curfs.begin();
111 QStringList::ConstIterator fsmount=mountList.begin(); 112 QStringList::ConstIterator fsmount=mountList.begin();
112 QStringList::ConstIterator fsTit=fsT.begin(); 113 QStringList::ConstIterator fsTit=fsT.begin();
113 114
114 for (; it!=curdisks.end(); ++it, ++fsit) { 115 for (; it!=curdisks.end(); ++it, ++fsit) {
115 if ( !frst ) { 116 if ( !frst ) {
116 QFrame *f = new QFrame( this ); 117 QFrame *f = new QFrame( this );
117 vb->addWidget(f); 118 vb->addWidget(f);
118 f->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 119 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
119 lines.append(f); 120 lines.append(f);
120 f->show(); 121 f->show();
121 } frst=FALSE; 122 } frst=FALSE;
122 QString humanname=*it; 123 QString humanname=*it;
124// qDebug(humanname);
123 if ( isCF(humanname) ) 125 if ( isCF(humanname) )
124 humanname = tr("CF Card: "+*fsmount+" "+*fsTit+" "); 126 humanname = tr("CF Card: "+*fsmount+" "+*fsTit+" ");
125 else if ( humanname == "/dev/hda1" ) 127 else if ( humanname == "/dev/hda1" )
126 humanname = tr("Hard Disk "+*fsmount+" "+*fsTit+" "); 128 humanname = tr("Hard Disk "+*fsmount+" "+*fsTit+" ");
127 else if ( humanname.left(9) == "/dev/mmcd" ) 129 else if ( humanname.left(9) == "/dev/mmcd" )
128 humanname = tr("SD Card "+*fsmount+" "+*fsTit+" "); 130 humanname = tr("SD Card "+*fsmount+" "+*fsTit+" ");
129 else if ( humanname.left(7) == "/dev/hd" ) 131 else if ( humanname.left(7) == "/dev/hd" )
130 humanname = tr("Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" "; 132 humanname = tr("Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" ";
131 else if ( humanname.left(7) == "/dev/sd" ) 133 else if ( humanname.left(7) == "/dev/sd" )
132 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" "; 134 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" ";
133 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 135 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
134 humanname = tr("Internal Storage "+*fsmount+" "+*fsTit+"\n"); 136 humanname = tr("Int. Storage "+*fsmount+" "+*fsTit+"\n");
135 else if ( humanname.left(14) == "/dev/mtdblock/" ) 137 else if ( humanname.left(14) == "/dev/mtdblock/" )
136 humanname = tr("Internal Storage") + " " + humanname.mid(14)+" "+*fsmount+" "+*fsTit+" "; 138 humanname = tr("Int. Storage") + " " + humanname.mid(14)+" "+*fsmount+" "+*fsTit+" ";
137 else if ( humanname.left(13) == "/dev/mtdblock" ) 139 else if ( humanname.left(13) == "/dev/mtdblock" )
138 humanname = tr("Internal Storage") + " " + humanname.mid(13)+" "+*fsmount+" "+*fsTit+" "; 140 humanname = tr("Int. Storage") + " " + humanname.mid(13)+" "+*fsmount+" "+*fsTit+" ";
139 else if ( humanname.left(9) == "/dev/root" ) 141 else if ( humanname.left(9) == "/dev/root" )
140 humanname = tr("Internal Storage "+*fsmount+" "+*fsTit+" "); 142 humanname = tr("Int. Storage "+*fsmount+" "+*fsTit+" ");
141 // etc. 143 // etc.
142 MountInfo* mi = new MountInfo( *fsit, humanname, this ); 144 MountInfo* mi = new MountInfo( *fsit, humanname, this );
143 vb->addWidget(mi); 145 vb->addWidget(mi);
144 disks.insert(*fsit,mi); 146 disks.insert(*fsit,mi);
145 mi->show(); 147 mi->show();
146 fsmount++;fsTit++; 148 fsmount++;fsTit++;
147 } 149 }
148 vb->addStretch(); 150 vb->addStretch();
149 } else { 151 } else {
150 // just update them 152 // just update them
151 for (QDictIterator<MountInfo> i(disks); i.current(); ++i) 153 for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
152 i.current()->updateData(); 154 i.current()->updateData();
153 } 155 }
154#endif 156#endif
155} 157}
156 158
157 159
158MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name ) 160MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name )
159 : QWidget( parent, name ), title(ttl) 161 : QWidget( parent, name ), title(ttl)
160{ 162{
161 qDebug("new path is "+path); 163 qDebug("new path is "+path);
162 fs = new FileSystem( path ); 164 fs = new FileSystem( path );
163 QVBoxLayout *vb = new QVBoxLayout( this, 3 ); 165 QVBoxLayout *vb = new QVBoxLayout( this, 3 );
164 166
165 totalSize = new QLabel( this ); 167 totalSize = new QLabel( this );
166 vb->addWidget( totalSize ); 168 vb->addWidget( totalSize );
167 169
168 data = new GraphData(); 170 data = new GraphData();
169 graph = new BarGraph( this ); 171 graph = new BarGraph( this );
170 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 172 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
171 vb->addWidget( graph, 1 ); 173 vb->addWidget( graph, 1 );
172 graph->setData( data ); 174 graph->setData( data );
173 175
174 legend = new GraphLegend( this ); 176 legend = new GraphLegend( this );
175 legend->setOrientation(Horizontal); 177 legend->setOrientation(Horizontal);
176 vb->addWidget( legend ); 178 vb->addWidget( legend );
177 legend->setData( data ); 179 legend->setData( data );
178 180
179 updateData(); 181 updateData();
180} 182}
181 183
182MountInfo::~MountInfo() 184MountInfo::~MountInfo()
183{ 185{
184 delete data; 186 delete data;
185 delete fs; 187 delete fs;
186} 188}
187 189
188void MountInfo::updateData() 190void MountInfo::updateData()
189{ 191{
190 fs->update(); 192 fs->update();
191 193
192 long mult = fs->blockSize() / 1024; 194 long mult = fs->blockSize() / 1024;
193 long div = 1024 / fs->blockSize(); 195 long div = 1024 / fs->blockSize();
194 if ( !mult ) mult = 1; 196 if ( !mult ) mult = 1;
195 if ( !div ) div = 1; 197 if ( !div ) div = 1;
196 long total = fs->totalBlocks() * mult / div; 198 long total = fs->totalBlocks() * mult / div;
197 long avail = fs->availBlocks() * mult / div; 199 long avail = fs->availBlocks() * mult / div;
198 long used = total - avail; 200 long used = total - avail;
199 totalSize->setText( title + tr("Total: %1 kB").arg( total ) ); 201 totalSize->setText( title + tr(" : %1 kB").arg( total ) );
200 data->clear(); 202 data->clear();
201 data->addItem( tr("Used (%1 kB)").arg(used), used ); 203 data->addItem( tr("Used (%1 kB)").arg(used), used );
202 data->addItem( tr("Available (%1 kB)").arg(avail), avail ); 204 data->addItem( tr("Available (%1 kB)").arg(avail), avail );
203 graph->repaint( FALSE ); 205 graph->repaint( FALSE );
204 legend->update(); 206 legend->update();
205 graph->show(); 207 graph->show();
206 legend->show(); 208 legend->show();
207} 209}
208 210
209//--------------------------------------------------------------------------- 211//---------------------------------------------------------------------------
210 212
211FileSystem::FileSystem( const QString &p ) 213FileSystem::FileSystem( const QString &p )
212 : fspath( p ), blkSize(512), totalBlks(0), availBlks(0) 214 : fspath( p ), blkSize(512), totalBlks(0), availBlks(0)
213{ 215{
214 update(); 216 update();
215} 217}
216 218
217void FileSystem::update() 219void FileSystem::update()
218{ 220{
219#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 221#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
220 struct statfs fs; 222 struct statfs fs;
221 if ( !statfs( fspath.latin1(), &fs ) ) { 223 if ( !statfs( fspath.latin1(), &fs ) ) {
222 if( fspath.left(8) == "/mnt/ram") { //ugly hack openzaurus 224 if( fspath.left(8) == "/mnt/ram") { //ugly hack openzaurus
223 blkSize = fs.f_bsize; 225 blkSize = fs.f_bsize;
224 totalBlks = fs.f_blocks; 226 totalBlks = fs.f_blocks;
225 availBlks = fs.f_ffree; 227 availBlks = fs.f_ffree;
226 } else { 228 } else {
227 blkSize = fs.f_bsize; 229 blkSize = fs.f_bsize;
228 totalBlks = fs.f_blocks; 230 totalBlks = fs.f_blocks;
229 availBlks = fs.f_bavail; 231 availBlks = fs.f_bavail;
230 } 232 }
231 } else { 233 } else {
232 blkSize = 0; 234 blkSize = 0;
233 totalBlks = 0; 235 totalBlks = 0;
234 availBlks = 0; 236 availBlks = 0;
235 } 237 }
236#endif 238#endif
237} 239}
238 240