summaryrefslogtreecommitdiff
path: root/noncore/settings
authordrw <drw>2003-03-27 01:52:50 (UTC)
committer drw <drw>2003-03-27 01:52:50 (UTC)
commit0fc0190f424cf7e05f82a5c506db74c1e7f98e3b (patch) (unidiff)
treeb74eaef3196d6a29163e81ddbf7e7ed60486cc14 /noncore/settings
parent2196cc8e860a470796fdff12a1690818644d5a43 (diff)
downloadopie-0fc0190f424cf7e05f82a5c506db74c1e7f98e3b.zip
opie-0fc0190f424cf7e05f82a5c506db74c1e7f98e3b.tar.gz
opie-0fc0190f424cf7e05f82a5c506db74c1e7f98e3b.tar.bz2
Use libqpe's StorageInfo class for storage tab. This 1. reduces executable size by ~10% and 2. should now recognize MMC cards on iPaq's (can't verify myself, let me know if it doesn't work). Also added QScrollView on version tab so all info is visible when screen is landscape or input method is visible.
Diffstat (limited to 'noncore/settings') (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
@@ -18,6 +18,9 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
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>
22#include <qlayout.h> 25#include <qlayout.h>
23#include <qscrollview.h> 26#include <qscrollview.h>
@@ -33,137 +36,76 @@
33#include <mntent.h> 36#include <mntent.h>
34 #endif 37 #endif
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();
51 startTimer( 5000 ); 58 startTimer( 5000 );
52} 59}
53 60
54void StorageInfo::timerEvent(QTimerEvent*) 61void FileSysInfo::timerEvent(QTimerEvent*)
55{ 62{
56 updateMounts(); 63 updateMounts();
57} 64}
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 );
128 vb->addWidget(f); 97 vb->addWidget(f);
129 f->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 98 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
130 lines.append(f); 99 lines.append(f);
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" ) )
168 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Compact Flash memory card." ) ); 110 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Compact Flash memory card." ) );
169 else if ( tempstr == tr( "Ha" ) ) 111 else if ( tempstr == tr( "Ha" ) )
@@ -178,24 +120,32 @@ void StorageInfo::updateMounts()
178 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used of the temporary RAM disk." ) ); 120 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used of the temporary RAM disk." ) );
179 } 121 }
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)
184 i.current()->updateData(); 127 i.current()->updateData();
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 );
195 142
196 totalSize = new QLabel( this ); 143 totalSize = new QLabel( this );
197 vb->addWidget( totalSize ); 144 vb->addWidget( totalSize );
198 145
146 fs = filesys;
147 title = fs->name();
148
199 data = new GraphData(); 149 data = new GraphData();
200 graph = new BarGraph( this ); 150 graph = new BarGraph( this );
201 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 151 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
@@ -218,8 +168,6 @@ MountInfo::~MountInfo()
218 168
219void MountInfo::updateData() 169void MountInfo::updateData()
220{ 170{
221 fs->update();
222
223 long mult = fs->blockSize() / 1024; 171 long mult = fs->blockSize() / 1024;
224 long div = 1024 / fs->blockSize(); 172 long div = 1024 / fs->blockSize();
225 if ( !mult ) mult = 1; 173 if ( !mult ) mult = 1;
@@ -237,27 +185,3 @@ void MountInfo::updateData()
237 legend->show(); 185 legend->show();
238} 186}
239 187
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
@@ -30,60 +30,50 @@ class FileSystem;
30class MountInfo; 30class MountInfo;
31class QVBoxLayout; 31class QVBoxLayout;
32class QWidget; 32class QWidget;
33class StorageInfo;
33 34
34 35
35class StorageInfo : public QWidget 36class FileSysInfo : public QWidget
36{ 37{
37 Q_OBJECT 38 Q_OBJECT
38public: 39public:
39 StorageInfo( QWidget *parent=0, const char *name=0 ); 40 FileSysInfo( QWidget *parent=0, const char *name=0 );
40 41
41protected: 42protected:
42 void timerEvent(QTimerEvent*); 43 void timerEvent(QTimerEvent*);
43 44
44private: 45private:
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};
51 60
52class MountInfo : public QWidget 61class MountInfo : public QWidget
53{ 62{
54 Q_OBJECT 63 Q_OBJECT
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();
58 67
59 void updateData(); 68 void updateData();
69
70 FileSystem *fs;
60 71
61private: 72private:
62 QString title; 73 QString title;
63 FileSystem *fs;
64 QLabel *totalSize; 74 QLabel *totalSize;
65 GraphData *data; 75 GraphData *data;
66 Graph *graph; 76 Graph *graph;
67 GraphLegend *legend; 77 GraphLegend *legend;
68}; 78};
69 79
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
@@ -54,7 +54,7 @@ SystemInfo::SystemInfo( QWidget *parent, const char *name, WFlags )
54 lay->addWidget( tab ); 54 lay->addWidget( tab );
55 tab->addTab( new MemoryInfo( tab ), "sysinfo/memorytabicon", tr("Memory") ); 55 tab->addTab( new MemoryInfo( tab ), "sysinfo/memorytabicon", tr("Memory") );
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
59 tab->addTab( new LoadInfo( tab ), "sysinfo/cputabicon", tr("CPU") ); 59 tab->addTab( new LoadInfo( tab ), "sysinfo/cputabicon", tr("CPU") );
60 if ( advanced ) 60 if ( advanced )
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
@@ -27,6 +27,7 @@
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qpixmap.h> 28#include <qpixmap.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qscrollview.h>
30#include <qtextstream.h> 31#include <qtextstream.h>
31#include <qtimer.h> 32#include <qtimer.h>
32#include <qwhatsthis.h> 33#include <qwhatsthis.h>
@@ -42,7 +43,15 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
42{ 43{
43 setMinimumSize( 200, 150 ); 44 setMinimumSize( 200, 150 );
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
47 QString kernelVersionString; 56 QString kernelVersionString;
48 QFile file( "/proc/version" ); 57 QFile file( "/proc/version" );
@@ -78,7 +87,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
78 QHBoxLayout *hb1 = new QHBoxLayout( vb ); 87 QHBoxLayout *hb1 = new QHBoxLayout( vb );
79 hb1->setSpacing( 2 ); 88 hb1->setSpacing( 2 );
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" );
83 logo1 = logo1.smoothScale( 50, 55 ); 92 logo1 = logo1.smoothScale( 50, 55 );
84 QPixmap logo1Pixmap; 93 QPixmap logo1Pixmap;
@@ -87,7 +96,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
87 palmtopLogo->setFixedSize( 60, 60 ); 96 palmtopLogo->setFixedSize( 60, 60 );
88 hb1->addWidget( palmtopLogo, 0, Qt::AlignTop + Qt::AlignLeft ); 97 hb1->addWidget( palmtopLogo, 0, Qt::AlignTop + Qt::AlignLeft );
89 98
90 QLabel *palmtopVersion = new QLabel( this ); 99 QLabel *palmtopVersion = new QLabel( container );
91 palmtopVersion->setText( palmtopVersionString ); 100 palmtopVersion->setText( palmtopVersionString );
92 hb1->addWidget( palmtopVersion, 1, Qt::AlignTop + Qt::AlignLeft ); 101 hb1->addWidget( palmtopVersion, 1, Qt::AlignTop + Qt::AlignLeft );
93 102
@@ -95,7 +104,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
95 QHBoxLayout *hb2 = new QHBoxLayout( vb ); 104 QHBoxLayout *hb2 = new QHBoxLayout( vb );
96 hb1->setSpacing( 2 ); 105 hb1->setSpacing( 2 );
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" );
100 logo2 = logo2.smoothScale( 55, 60 ); 109 logo2 = logo2.smoothScale( 55, 60 );
101 QPixmap logo2Pixmap; 110 QPixmap logo2Pixmap;
@@ -104,7 +113,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
104 linuxLogo->setFixedSize( 60, 60 ); 113 linuxLogo->setFixedSize( 60, 60 );
105 hb2->addWidget( linuxLogo, 0, Qt::AlignTop + Qt::AlignLeft ); 114 hb2->addWidget( linuxLogo, 0, Qt::AlignTop + Qt::AlignLeft );
106 115
107 QLabel *kernelVersion = new QLabel( this ); 116 QLabel *kernelVersion = new QLabel( container );
108 kernelVersion->setText( kernelVersionString ); 117 kernelVersion->setText( kernelVersionString );
109 hb2->addWidget( kernelVersion, 1, Qt::AlignTop + Qt::AlignLeft ); 118 hb2->addWidget( kernelVersion, 1, Qt::AlignTop + Qt::AlignLeft );
110 119
@@ -112,7 +121,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
112 QHBoxLayout *hb3 = new QHBoxLayout( vb ); 121 QHBoxLayout *hb3 = new QHBoxLayout( vb );
113 hb3->setSpacing( 2 ); 122 hb3->setSpacing( 2 );
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" );
117 logo3 = logo3.smoothScale( 50, 55 ); 126 logo3 = logo3.smoothScale( 50, 55 );
118 QPixmap logo3Pixmap; 127 QPixmap logo3Pixmap;
@@ -131,7 +140,7 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f )
131 systemString.append( tr( "<p>Vendor: " ) ); 140 systemString.append( tr( "<p>Vendor: " ) );
132 systemString.append( ODevice::inst()->vendorString() ); 141 systemString.append( ODevice::inst()->vendorString() );
133 142
134 QLabel *systemVersion = new QLabel( this ); 143 QLabel *systemVersion = new QLabel( container );
135 systemVersion->setText( systemString ); 144 systemVersion->setText( systemString );
136 hb3->addWidget( systemVersion, 1, Qt::AlignTop + Qt::AlignLeft ); 145 hb3->addWidget( systemVersion, 1, Qt::AlignTop + Qt::AlignLeft );
137 146