summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/storage.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/storage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/storage.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/noncore/settings/sysinfo/storage.cpp b/noncore/settings/sysinfo/storage.cpp
index b369ff1..c33663e 100644
--- a/noncore/settings/sysinfo/storage.cpp
+++ b/noncore/settings/sysinfo/storage.cpp
@@ -1,72 +1,73 @@
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 <qwhatsthis.h>
25
25#include "graph.h" 26#include "graph.h"
26#include "storage.h" 27#include "storage.h"
27 28
28#include <stdio.h> 29#include <stdio.h>
29 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 30 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
30#include <sys/vfs.h> 31#include <sys/vfs.h>
31#include <mntent.h> 32#include <mntent.h>
32 #endif 33 #endif
33 34
34StorageInfo::StorageInfo( QWidget *parent, const char *name ) 35StorageInfo::StorageInfo( QWidget *parent, const char *name )
35 : QWidget( parent, name ) 36 : QWidget( parent, name )
36{ 37{
37 vb = 0; 38 vb = 0;
38 disks.setAutoDelete(TRUE); 39 disks.setAutoDelete(TRUE);
39 lines.setAutoDelete(TRUE); 40 lines.setAutoDelete(TRUE);
40 updateMounts(); 41 updateMounts();
41 startTimer( 5000 ); 42 startTimer( 5000 );
42} 43}
43 44
44void StorageInfo::timerEvent(QTimerEvent*) 45void StorageInfo::timerEvent(QTimerEvent*)
45{ 46{
46 updateMounts(); 47 updateMounts();
47} 48}
48 49
49static bool isCF(const QString& m) 50static bool isCF(const QString& m)
50{ 51{
51 FILE* f = fopen("/var/run/stab", "r"); 52 FILE* f = fopen("/var/run/stab", "r");
52 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 53 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
53 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 54 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
54 if ( f ) { 55 if ( f ) {
55 char line[1024]; 56 char line[1024];
56 char devtype[80]; 57 char devtype[80];
57 char devname[80]; 58 char devname[80];
58 while ( fgets( line, 1024, f ) ) { 59 while ( fgets( line, 1024, f ) ) {
59 // 0 ide ide-cs 0 hda 3 0 60 // 0 ide ide-cs 0 hda 3 0
60 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) { 61 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) {
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);
68 } 69 }
69 return FALSE; 70 return FALSE;
70} 71}
71 72
72void StorageInfo::updateMounts() 73void StorageInfo::updateMounts()
@@ -78,119 +79,135 @@ void StorageInfo::updateMounts()
78 QStringList curfs; 79 QStringList curfs;
79 QStringList mountList; 80 QStringList mountList;
80 QStringList fsT; 81 QStringList fsT;
81 bool rebuild = FALSE; 82 bool rebuild = FALSE;
82 int n=0; 83 int n=0;
83 if ( mntfp ) { 84 if ( mntfp ) {
84 while ( (me = getmntent( mntfp )) != 0 ) { 85 while ( (me = getmntent( mntfp )) != 0 ) {
85 QString fs = me->mnt_fsname; 86 QString fs = me->mnt_fsname;
86 qDebug(fs+" "+(QString)me->mnt_type); 87 qDebug(fs+" "+(QString)me->mnt_type);
87 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 88 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
88 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 89 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
89 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs") { 90 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs") {
90 n++; 91 n++;
91 curdisks.append(fs); 92 curdisks.append(fs);
92 QString d = me->mnt_dir; 93 QString d = me->mnt_dir;
93 curfs.append(d); 94 curfs.append(d);
94 QString mount = me->mnt_dir; 95 QString mount = me->mnt_dir;
95 mountList.append(mount); 96 mountList.append(mount);
96 QString t = me->mnt_type; 97 QString t = me->mnt_type;
97 fsT.append(t); 98 fsT.append(t);
98 if ( !disks.find(d) ) 99 if ( !disks.find(d) )
99 rebuild = TRUE; 100 rebuild = TRUE;
100 } 101 }
101 } 102 }
102 endmntent( mntfp ); 103 endmntent( mntfp );
103 } 104 }
104 if ( rebuild || n != (int)disks.count() ) { 105 if ( rebuild || n != (int)disks.count() ) {
105 disks.clear(); 106 disks.clear();
106 lines.clear(); 107 lines.clear();
107 delete vb; 108 delete vb;
108 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 ); 109 vb = new QVBoxLayout( this, n > 3 ? 1 : 5 );
109 bool frst=TRUE; 110 bool frst=TRUE;
110 QStringList::ConstIterator it=curdisks.begin(); 111 QStringList::ConstIterator it=curdisks.begin();
111 QStringList::ConstIterator fsit=curfs.begin(); 112 QStringList::ConstIterator fsit=curfs.begin();
112 QStringList::ConstIterator fsmount=mountList.begin(); 113 QStringList::ConstIterator fsmount=mountList.begin();
113 QStringList::ConstIterator fsTit=fsT.begin(); 114 QStringList::ConstIterator fsTit=fsT.begin();
114 115
115 for (; it!=curdisks.end(); ++it, ++fsit) { 116 for (; it!=curdisks.end(); ++it, ++fsit) {
116 if ( !frst ) { 117 if ( !frst ) {
117 QFrame *f = new QFrame( this ); 118 QFrame *f = new QFrame( this );
118 vb->addWidget(f); 119 vb->addWidget(f);
119 f->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 120 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
120 lines.append(f); 121 lines.append(f);
121 f->show(); 122 f->show();
122 } frst=FALSE; 123 } frst=FALSE;
123 QString humanname=*it; 124 QString humanname=*it;
124// qDebug(humanname); 125// qDebug(humanname);
125 if ( isCF(humanname) ) 126 if ( isCF(humanname) )
126 humanname = tr("CF Card: "+*fsmount+" "+*fsTit+" "); 127 humanname = tr( "CF Card: " );
127 else if ( humanname == "/dev/hda1" ) 128 else if ( humanname == "/dev/hda1" )
128 humanname = tr("Hard Disk "+*fsmount+" "+*fsTit+" "); 129 humanname = tr( "Hard Disk " );
129 else if ( humanname.left(9) == "/dev/mmcd" ) 130 else if ( humanname.left(9) == "/dev/mmcd" )
130 humanname = tr("SD Card "+*fsmount+" "+*fsTit+" "); 131 humanname = tr( "SD Card " );
131 else if ( humanname.left(7) == "/dev/hd" ) 132 else if ( humanname.left(7) == "/dev/hd" )
132 humanname = tr("Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" "; 133 humanname = tr( "Hard Disk /dev/hd " );
133 else if ( humanname.left(7) == "/dev/sd" ) 134 else if ( humanname.left(7) == "/dev/sd" )
134 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7)+" "+*fsmount+" "+*fsTit+" "; 135 humanname = tr( "SCSI Hard Disk /dev/sd " );
135 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 136 else if ( humanname == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
136 humanname = tr("Int. Storage "+*fsmount+" "+*fsTit+"\n"); 137 humanname = tr( "Int. Storage " );
137 else if ( humanname.left(14) == "/dev/mtdblock/" ) 138 else if ( humanname.left(14) == "/dev/mtdblock/" )
138 humanname = tr("Int. Storage") + " " + humanname.mid(14)+" "+*fsmount+" "+*fsTit+" "; 139 humanname = tr( "Int. Storage /dev/mtdblock/ " );
139 else if ( humanname.left(13) == "/dev/mtdblock" ) 140 else if ( humanname.left(13) == "/dev/mtdblock" )
140 humanname = tr("Int. Storage") + " " + humanname.mid(13)+" "+*fsmount+" "+*fsTit+" "; 141 humanname = tr( "Int. Storage /dev/mtdblock " );
141 else if ( humanname.left(9) == "/dev/root" ) 142 else if ( humanname.left(9) == "/dev/root" )
142 humanname = tr("Int. Storage "+*fsmount+" "+*fsTit+" "); 143 humanname = tr( "Int. Storage " );
143 // etc. 144 // etc.
145 humanname.append( *fsmount );
146 humanname.append( " " );
147 humanname.append( *fsTit );
148 humanname.append( " " );
149
144 MountInfo* mi = new MountInfo( *fsit, humanname, this ); 150 MountInfo* mi = new MountInfo( *fsit, humanname, this );
145 vb->addWidget(mi); 151 vb->addWidget(mi);
146 disks.insert(*fsit,mi); 152 disks.insert(*fsit,mi);
147 mi->show(); 153 mi->show();
148 fsmount++;fsTit++; 154 fsmount++;fsTit++;
155 QString tempstr = humanname.left( 2 );
156 if ( tempstr == tr( "CF" ) )
157 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Compact Flash memory card." ) );
158 else if ( tempstr == tr( "Ha" ) )
159 QWhatsThis::add( mi, tr( "This graph represents how much storage is currently used on this hard drive." ) );
160 else if ( tempstr == tr( "SD" ) )
161 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Secure Digital memory card." ) );
162 else if ( tempstr == tr( "SC" ) )
163 QWhatsThis::add( mi, tr( "This graph represents how much storage is currently used on this hard drive." ) );
164 else if ( tempstr == tr( "In" ) )
165 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used of the built-in memory (i.e. Flash memory) on this handheld device." ) );
149 } 166 }
150 vb->addStretch(); 167 vb->addStretch();
151 } else { 168 } else {
152 // just update them 169 // just update them
153 for (QDictIterator<MountInfo> i(disks); i.current(); ++i) 170 for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
154 i.current()->updateData(); 171 i.current()->updateData();
155 } 172 }
156#endif 173#endif
157} 174}
158 175
159 176
160MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name ) 177MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name )
161 : QWidget( parent, name ), title(ttl) 178 : QWidget( parent, name ), title(ttl)
162{ 179{
163 qDebug("new path is "+path); 180 qDebug("new path is "+path);
164 fs = new FileSystem( path ); 181 fs = new FileSystem( path );
165 QVBoxLayout *vb = new QVBoxLayout( this, 3 ); 182 QVBoxLayout *vb = new QVBoxLayout( this, 3 );
166 183
167 totalSize = new QLabel( this ); 184 totalSize = new QLabel( this );
168 vb->addWidget( totalSize ); 185 vb->addWidget( totalSize );
169 186
170 data = new GraphData(); 187 data = new GraphData();
171 graph = new BarGraph( this ); 188 graph = new BarGraph( this );
172 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 189 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
173 vb->addWidget( graph, 1 ); 190 vb->addWidget( graph, 1 );
174 graph->setData( data ); 191 graph->setData( data );
175 192
176 legend = new GraphLegend( this ); 193 legend = new GraphLegend( this );
177 legend->setOrientation(Horizontal); 194 legend->setOrientation(Horizontal);
178 vb->addWidget( legend ); 195 vb->addWidget( legend );
179 legend->setData( data ); 196 legend->setData( data );
180 197
181 updateData(); 198 updateData();
182} 199}
183 200
184MountInfo::~MountInfo() 201MountInfo::~MountInfo()
185{ 202{
186 delete data; 203 delete data;
187 delete fs; 204 delete fs;
188} 205}
189 206
190void MountInfo::updateData() 207void MountInfo::updateData()
191{ 208{
192 fs->update(); 209 fs->update();
193 210
194 long mult = fs->blockSize() / 1024; 211 long mult = fs->blockSize() / 1024;
195 long div = 1024 / fs->blockSize(); 212 long div = 1024 / fs->blockSize();
196 if ( !mult ) mult = 1; 213 if ( !mult ) mult = 1;