summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/storage.cpp198
-rw-r--r--noncore/settings/sysinfo/storage.h44
-rw-r--r--noncore/settings/sysinfo/sysinfo.cpp2
-rw-r--r--noncore/settings/sysinfo/versioninfo.cpp23
4 files changed, 95 insertions, 172 deletions
diff --git a/noncore/settings/sysinfo/storage.cpp b/noncore/settings/sysinfo/storage.cpp
index eb157ef..c4474d5 100644
--- a/noncore/settings/sysinfo/storage.cpp
+++ b/noncore/settings/sysinfo/storage.cpp
@@ -20,2 +20,5 @@
20// additions copyright 2002 by L.J. Potter 20// additions copyright 2002 by L.J. Potter
21
22#include <qpe/storage.h>
23
21#include <qlabel.h> 24#include <qlabel.h>
@@ -35,16 +38,20 @@
35 38
36StorageInfo::StorageInfo( QWidget *parent, const char *name ) 39FileSysInfo::FileSysInfo( QWidget *parent, const char *name )
37 : QWidget( parent, name ) 40 : QWidget( parent, name )
38{ 41{
39 QVBoxLayout *tmpvb = new QVBoxLayout( this ); 42 QVBoxLayout *tmpvb = new QVBoxLayout( this );
40 QScrollView *sv = new QScrollView( this ); 43 QScrollView *sv = new QScrollView( this );
41 tmpvb->addWidget( sv, 0, 0 ); 44 tmpvb->addWidget( sv, 0, 0 );
42 sv->setResizePolicy( QScrollView::AutoOneFit ); 45 sv->setResizePolicy( QScrollView::AutoOneFit );
43 sv->setFrameStyle( QFrame::NoFrame ); 46 sv->setFrameStyle( QFrame::NoFrame );
44 container = new QWidget( sv->viewport() ); 47 container = new QWidget( sv->viewport() );
45 sv->addChild( container ); 48 sv->addChild( container );
46 vb = 0x0; 49 vb = 0x0;
47 50
48 disks.setAutoDelete(TRUE); 51 storage = new StorageInfo( this );
52 connect( storage, SIGNAL( disksChanged() ), this, SLOT( disksChanged() ) );
53
49 lines.setAutoDelete(TRUE); 54 lines.setAutoDelete(TRUE);
55
56 rebuildDisks = TRUE;
50 updateMounts(); 57 updateMounts();
@@ -53,3 +60,3 @@ StorageInfo::StorageInfo( QWidget *parent, const char *name )
53 60
54void StorageInfo::timerEvent(QTimerEvent*) 61void FileSysInfo::timerEvent(QTimerEvent*)
55{ 62{
@@ -58,70 +65,32 @@ void StorageInfo::timerEvent(QTimerEvent*)
58 65
59static bool isCF(const QString& m) 66void FileSysInfo::updateMounts()
60{
61 FILE* f = fopen("/var/run/stab", "r");
62 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
63 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
64 if ( f ) {
65 char line[1024];
66 char devtype[80];
67 char devname[80];
68 while ( fgets( line, 1024, f ) ) {
69 // 0 ide ide-cs 0 hda 3 0
70 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) {
71 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
72 fclose(f);
73 return TRUE;
74 }
75 }
76 }
77 fclose(f);
78 }
79 return FALSE;
80}
81
82void StorageInfo::updateMounts()
83{ 67{
84#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 68 storage->update();
85 struct mntent *me; 69
86 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 70 if ( rebuildDisks )
87 QStringList curdisks; 71 {
88 QStringList curfs; 72 // Cannot auto delete QDict<MountInfo> disks because it seems to delete
89 QStringList mountList; 73 // the filesystem object as well causing a segfault
90 QStringList fsT; 74 MountInfo *mi;
91 bool rebuild = FALSE; 75 for ( QDictIterator<MountInfo> delit(disks); delit.current(); ++delit )
92 int n=0; 76 {
93 if ( mntfp ) { 77 mi = delit.current();
94 while ( (me = getmntent( mntfp )) != 0 ) { 78 mi->fs = 0x0;
95 QString fs = me->mnt_fsname; 79 delete mi;
96 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
97 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
98 || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs"
99 || fs.left(5) == "tmpfs" ) {
100 n++;
101 curdisks.append(fs);
102 QString d = me->mnt_dir;
103 curfs.append(d);
104 QString mount = me->mnt_dir;
105 mountList.append(mount);
106 QString t = me->mnt_type;
107 fsT.append(t);
108 if ( !disks.find(d) )
109 rebuild = TRUE;
110 }
111 } 80 }
112 endmntent( mntfp );
113 }
114 if ( rebuild || n != (int)disks.count() ) {
115 disks.clear(); 81 disks.clear();
116 lines.clear(); 82 lines.clear();
83
117 delete vb; 84 delete vb;
118 vb = new QVBoxLayout( container/*, n > 3 ? 1 : 5*/ ); 85 vb = new QVBoxLayout( container/*, n > 3 ? 1 : 5*/ );
119 bool frst=TRUE;
120 QStringList::ConstIterator it = curdisks.begin();
121 QStringList::ConstIterator fsit = curfs.begin();
122 QStringList::ConstIterator fsmount = mountList.begin();
123 QStringList::ConstIterator fsTit = fsT.begin();
124 86
125 for (; it!=curdisks.end(); ++it, ++fsit) { 87 bool frst=TRUE;
126 if ( !frst ) { 88
89 FileSystem *fs;
90 for ( QListIterator<FileSystem> it(storage->fileSystems()); it.current(); ++it )
91 {
92 fs = it.current();
93
94 if ( !frst )
95 {
127 QFrame *f = new QFrame( container ); 96 QFrame *f = new QFrame( container );
@@ -131,37 +100,10 @@ void StorageInfo::updateMounts()
131 f->show(); 100 f->show();
132 } frst=FALSE; 101 }
133 QString humanname=*it; 102 frst = FALSE;
134 if ( isCF(humanname) ) 103
135 humanname = tr( "CF Card: " ); 104 MountInfo *mi = new MountInfo( fs, container );
136 else if ( humanname == "/dev/hda1" ) 105 vb->addWidget( mi );
137 humanname = tr( "Hard Disk " ); 106 disks.insert( fs->path(), mi );
138
139 else if ( humanname.left(9) == "/dev/mmcd" )
140 humanname = tr( "SD Card " );
141
142 else if ( humanname.left(7) == "/dev/hd" )
143 humanname = tr( "Hard Disk /dev/hd " );
144
145 else if ( humanname.left(7) == "/dev/sd" )
146 humanname = tr( "SCSI Hard Disk /dev/sd " );
147
148 else if ( humanname == "/dev/mtdblock1"
149 || humanname.left(13) == "/dev/mtdblock"
150 || humanname.left(9) == "/dev/root")
151 humanname = tr( "Int. Storage " );
152
153 else if ( humanname.left(5) == "tmpfs" )
154 humanname = tr( "RAM disk" );
155 // etc.
156 humanname.append( *fsmount );
157 humanname.append( " " );
158 humanname.append( *fsTit );
159 humanname.append( " " );
160
161 MountInfo* mi = new MountInfo( *fsit, humanname, container );
162 vb->addWidget(mi);
163 disks.insert(*fsit,mi);
164 mi->show(); 107 mi->show();
165 fsmount++;fsTit++; 108 QString tempstr = fs->name().left( 2 );
166 QString tempstr = humanname.left( 2 );
167 if ( tempstr == tr( "CF" ) ) 109 if ( tempstr == tr( "CF" ) )
@@ -180,4 +122,5 @@ void StorageInfo::updateMounts()
180 vb->addStretch(); 122 vb->addStretch();
181 } else { 123 }
182 // just update them 124 else
125 {
183 for (QDictIterator<MountInfo> i(disks); i.current(); ++i) 126 for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
@@ -185,10 +128,14 @@ void StorageInfo::updateMounts()
185 } 128 }
186#endif 129
130 rebuildDisks = FALSE;
187} 131}
188 132
133void FileSysInfo::disksChanged()
134{
135 rebuildDisks = TRUE;
136}
189 137
190MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name ) 138MountInfo::MountInfo( FileSystem *filesys, QWidget *parent, const char *name )
191 : QWidget( parent, name ), title(ttl) 139 : QWidget( parent, name )
192{ 140{
193 fs = new FileSystem( path );
194 QVBoxLayout *vb = new QVBoxLayout( this, 3 ); 141 QVBoxLayout *vb = new QVBoxLayout( this, 3 );
@@ -198,2 +145,5 @@ MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent,
198 145
146 fs = filesys;
147 title = fs->name();
148
199 data = new GraphData(); 149 data = new GraphData();
@@ -220,4 +170,2 @@ void MountInfo::updateData()
220{ 170{
221 fs->update();
222
223 long mult = fs->blockSize() / 1024; 171 long mult = fs->blockSize() / 1024;
@@ -239,25 +187 @@ void MountInfo::updateData()
239
240//---------------------------------------------------------------------------
241
242FileSystem::FileSystem( const QString &p )
243 : fspath( p ), blkSize(512), totalBlks(0), availBlks(0)
244{
245 update();
246}
247
248void FileSystem::update()
249{
250#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
251 struct statfs fs;
252 if ( !statfs( fspath.latin1(), &fs ) ) {
253 blkSize = fs.f_bsize;
254 totalBlks = fs.f_blocks;
255 availBlks = fs.f_bavail;
256 } else {
257 blkSize = 0;
258 totalBlks = 0;
259 availBlks = 0;
260 }
261#endif
262}
263
diff --git a/noncore/settings/sysinfo/storage.h b/noncore/settings/sysinfo/storage.h
index 7e8b4e0..b8564af 100644
--- a/noncore/settings/sysinfo/storage.h
+++ b/noncore/settings/sysinfo/storage.h
@@ -32,5 +32,6 @@ class QVBoxLayout;
32class QWidget; 32class QWidget;
33class StorageInfo;
33 34
34 35
35class StorageInfo : public QWidget 36class FileSysInfo : public QWidget
36{ 37{
@@ -38,3 +39,3 @@ class StorageInfo : public QWidget
38public: 39public:
39 StorageInfo( QWidget *parent=0, const char *name=0 ); 40 FileSysInfo( QWidget *parent=0, const char *name=0 );
40 41
@@ -45,6 +46,14 @@ private:
45 void updateMounts(); 46 void updateMounts();
46 QDict<MountInfo> disks; 47
47 QList<QFrame> lines; 48 QWidget *container;
48 QVBoxLayout *vb; 49 QVBoxLayout *vb;
49 QWidget *container; 50
51 StorageInfo *storage;
52 QDict<MountInfo> disks;
53 QList<QFrame> lines;
54
55 bool rebuildDisks;
56
57private slots:
58 void disksChanged();
50}; 59};
@@ -55,3 +64,3 @@ class MountInfo : public QWidget
55public: 64public:
56 MountInfo( const QString &path, const QString &ttl, QWidget *parent=0, const char *name=0 ); 65 MountInfo( FileSystem *filesys=0, QWidget *parent=0, const char *name=0 );
57 ~MountInfo(); 66 ~MountInfo();
@@ -59,2 +68,4 @@ public:
59 void updateData(); 68 void updateData();
69
70 FileSystem *fs;
60 71
@@ -62,3 +73,2 @@ private:
62 QString title; 73 QString title;
63 FileSystem *fs;
64 QLabel *totalSize; 74 QLabel *totalSize;
@@ -69,21 +79 @@ private:
69
70class FileSystem
71{
72public:
73 FileSystem( const QString &p );
74
75 void update();
76
77 const QString &path() const { return fspath; }
78 long blockSize() const { return blkSize; }
79 long totalBlocks() const { return totalBlks; }
80 long availBlocks() const { return availBlks; }
81
82private:
83 QString fspath;
84 long blkSize;
85 long totalBlks;
86 long availBlks;
87};
88
89
diff --git a/noncore/settings/sysinfo/sysinfo.cpp b/noncore/settings/sysinfo/sysinfo.cpp
index c3bdae5..0c5a969 100644
--- a/noncore/settings/sysinfo/sysinfo.cpp
+++ b/noncore/settings/sysinfo/sysinfo.cpp
@@ -56,3 +56,3 @@ SystemInfo::SystemInfo( QWidget *parent, const char *name, WFlags )
56#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 56#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
57 tab->addTab( new StorageInfo( tab ), "sysinfo/storagetabicon", tr("Storage") ); 57 tab->addTab( new FileSysInfo( tab ), "sysinfo/storagetabicon", tr("Storage") );
58#endif 58#endif
diff --git a/noncore/settings/sysinfo/versioninfo.cpp b/noncore/settings/sysinfo/versioninfo.cpp
index 9a444df..801af29 100644
--- a/noncore/settings/sysinfo/versioninfo.cpp
+++ b/noncore/settings/sysinfo/versioninfo.cpp
@@ -29,2 +29,3 @@
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qscrollview.h>
30#include <qtextstream.h> 31#include <qtextstream.h>
@@ -44,3 +45,11 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
44 45
45 QVBoxLayout *vb = new QVBoxLayout( this, 4 ); 46 QVBoxLayout *tmpvb = new QVBoxLayout( this );
47 QScrollView *sv = new QScrollView( this );
48 tmpvb->addWidget( sv, 0, 0 );
49 sv->setResizePolicy( QScrollView::AutoOneFit );
50 sv->setFrameStyle( QFrame::NoFrame );
51 QWidget *container = new QWidget( sv->viewport() );
52 sv->addChild( container );
53
54 QVBoxLayout *vb = new QVBoxLayout( container, 4 );
46 55
@@ -80,3 +89,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
80 89
81 QLabel *palmtopLogo = new QLabel( this ); 90 QLabel *palmtopLogo = new QLabel( container );
82 QImage logo1 = Resource::loadImage( "logo/opielogo" ); 91 QImage logo1 = Resource::loadImage( "logo/opielogo" );
@@ -89,3 +98,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
89 98
90 QLabel *palmtopVersion = new QLabel( this ); 99 QLabel *palmtopVersion = new QLabel( container );
91 palmtopVersion->setText( palmtopVersionString ); 100 palmtopVersion->setText( palmtopVersionString );
@@ -97,3 +106,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
97 106
98 QLabel *linuxLogo = new QLabel( this ); 107 QLabel *linuxLogo = new QLabel( container );
99 QImage logo2 = Resource::loadImage( "logo/tux-logo" ); 108 QImage logo2 = Resource::loadImage( "logo/tux-logo" );
@@ -106,3 +115,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
106 115
107 QLabel *kernelVersion = new QLabel( this ); 116 QLabel *kernelVersion = new QLabel( container );
108 kernelVersion->setText( kernelVersionString ); 117 kernelVersion->setText( kernelVersionString );
@@ -114,3 +123,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
114 123
115 QLabel *palmtopLogo3 = new QLabel( this ); 124 QLabel *palmtopLogo3 = new QLabel( container );
116 QImage logo3 = Resource::loadImage( "sysinfo/pda" ); 125 QImage logo3 = Resource::loadImage( "sysinfo/pda" );
@@ -133,3 +142,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
133 142
134 QLabel *systemVersion = new QLabel( this ); 143 QLabel *systemVersion = new QLabel( container );
135 systemVersion->setText( systemString ); 144 systemVersion->setText( systemString );