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