-rw-r--r-- | noncore/settings/sysinfo/storage.cpp | 198 | ||||
-rw-r--r-- | noncore/settings/sysinfo/storage.h | 44 | ||||
-rw-r--r-- | noncore/settings/sysinfo/sysinfo.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/sysinfo/versioninfo.cpp | 23 |
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 @@ // additions copyright 2002 by L.J. Potter + +#include <qpe/storage.h> + #include <qlabel.h> @@ -35,16 +38,20 @@ -StorageInfo::StorageInfo( QWidget *parent, const char *name ) +FileSysInfo::FileSysInfo( QWidget *parent, const char *name ) : QWidget( parent, name ) { - QVBoxLayout *tmpvb = new QVBoxLayout( this ); - QScrollView *sv = new QScrollView( this ); - tmpvb->addWidget( sv, 0, 0 ); - sv->setResizePolicy( QScrollView::AutoOneFit ); - sv->setFrameStyle( QFrame::NoFrame ); - container = new QWidget( sv->viewport() ); - sv->addChild( container ); + QVBoxLayout *tmpvb = new QVBoxLayout( this ); + QScrollView *sv = new QScrollView( this ); + tmpvb->addWidget( sv, 0, 0 ); + sv->setResizePolicy( QScrollView::AutoOneFit ); + sv->setFrameStyle( QFrame::NoFrame ); + container = new QWidget( sv->viewport() ); + sv->addChild( container ); vb = 0x0; - disks.setAutoDelete(TRUE); + storage = new StorageInfo( this ); + connect( storage, SIGNAL( disksChanged() ), this, SLOT( disksChanged() ) ); + lines.setAutoDelete(TRUE); + + rebuildDisks = TRUE; updateMounts(); @@ -53,3 +60,3 @@ StorageInfo::StorageInfo( QWidget *parent, const char *name ) -void StorageInfo::timerEvent(QTimerEvent*) +void FileSysInfo::timerEvent(QTimerEvent*) { @@ -58,70 +65,32 @@ void StorageInfo::timerEvent(QTimerEvent*) -static bool isCF(const QString& m) -{ - FILE* f = fopen("/var/run/stab", "r"); - if (!f) f = fopen("/var/state/pcmcia/stab", "r"); - if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); - if ( f ) { - char line[1024]; - char devtype[80]; - char devname[80]; - while ( fgets( line, 1024, f ) ) { - // 0 ide ide-cs 0 hda 3 0 - if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) { - if ( QString(devtype) == "ide" && m.find(devname)>0 ) { - fclose(f); - return TRUE; - } - } - } - fclose(f); - } - return FALSE; -} - -void StorageInfo::updateMounts() +void FileSysInfo::updateMounts() { -#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) - struct mntent *me; - FILE *mntfp = setmntent( "/etc/mtab", "r" ); - QStringList curdisks; - QStringList curfs; - QStringList mountList; - QStringList fsT; - bool rebuild = FALSE; - int n=0; - if ( mntfp ) { - while ( (me = getmntent( mntfp )) != 0 ) { - QString fs = me->mnt_fsname; - if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" - || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" - || fs.left(9) == "/dev/root" || fs.left(5) == "/ramfs" - || fs.left(5) == "tmpfs" ) { - n++; - curdisks.append(fs); - QString d = me->mnt_dir; - curfs.append(d); - QString mount = me->mnt_dir; - mountList.append(mount); - QString t = me->mnt_type; - fsT.append(t); - if ( !disks.find(d) ) - rebuild = TRUE; - } + storage->update(); + + if ( rebuildDisks ) + { + // Cannot auto delete QDict<MountInfo> disks because it seems to delete + // the filesystem object as well causing a segfault + MountInfo *mi; + for ( QDictIterator<MountInfo> delit(disks); delit.current(); ++delit ) + { + mi = delit.current(); + mi->fs = 0x0; + delete mi; } - endmntent( mntfp ); - } - if ( rebuild || n != (int)disks.count() ) { disks.clear(); lines.clear(); + delete vb; vb = new QVBoxLayout( container/*, n > 3 ? 1 : 5*/ ); - bool frst=TRUE; - QStringList::ConstIterator it = curdisks.begin(); - QStringList::ConstIterator fsit = curfs.begin(); - QStringList::ConstIterator fsmount = mountList.begin(); - QStringList::ConstIterator fsTit = fsT.begin(); - for (; it!=curdisks.end(); ++it, ++fsit) { - if ( !frst ) { + bool frst=TRUE; + + FileSystem *fs; + for ( QListIterator<FileSystem> it(storage->fileSystems()); it.current(); ++it ) + { + fs = it.current(); + + if ( !frst ) + { QFrame *f = new QFrame( container ); @@ -131,37 +100,10 @@ void StorageInfo::updateMounts() f->show(); - } frst=FALSE; - QString humanname=*it; - if ( isCF(humanname) ) - humanname = tr( "CF Card: " ); - else if ( humanname == "/dev/hda1" ) - humanname = tr( "Hard Disk " ); - - else if ( humanname.left(9) == "/dev/mmcd" ) - humanname = tr( "SD Card " ); - - else if ( humanname.left(7) == "/dev/hd" ) - humanname = tr( "Hard Disk /dev/hd " ); - - else if ( humanname.left(7) == "/dev/sd" ) - humanname = tr( "SCSI Hard Disk /dev/sd " ); - - else if ( humanname == "/dev/mtdblock1" - || humanname.left(13) == "/dev/mtdblock" - || humanname.left(9) == "/dev/root") - humanname = tr( "Int. Storage " ); - - else if ( humanname.left(5) == "tmpfs" ) - humanname = tr( "RAM disk" ); - // etc. - humanname.append( *fsmount ); - humanname.append( " " ); - humanname.append( *fsTit ); - humanname.append( " " ); - - MountInfo* mi = new MountInfo( *fsit, humanname, container ); - vb->addWidget(mi); - disks.insert(*fsit,mi); + } + frst = FALSE; + + MountInfo *mi = new MountInfo( fs, container ); + vb->addWidget( mi ); + disks.insert( fs->path(), mi ); mi->show(); - fsmount++;fsTit++; - QString tempstr = humanname.left( 2 ); + QString tempstr = fs->name().left( 2 ); if ( tempstr == tr( "CF" ) ) @@ -180,4 +122,5 @@ void StorageInfo::updateMounts() vb->addStretch(); - } else { - // just update them + } + else + { for (QDictIterator<MountInfo> i(disks); i.current(); ++i) @@ -185,10 +128,14 @@ void StorageInfo::updateMounts() } -#endif + + rebuildDisks = FALSE; } +void FileSysInfo::disksChanged() +{ + rebuildDisks = TRUE; +} -MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, const char *name ) - : QWidget( parent, name ), title(ttl) +MountInfo::MountInfo( FileSystem *filesys, QWidget *parent, const char *name ) + : QWidget( parent, name ) { - fs = new FileSystem( path ); QVBoxLayout *vb = new QVBoxLayout( this, 3 ); @@ -198,2 +145,5 @@ MountInfo::MountInfo( const QString &path, const QString &ttl, QWidget *parent, + fs = filesys; + title = fs->name(); + data = new GraphData(); @@ -220,4 +170,2 @@ void MountInfo::updateData() { - fs->update(); - long mult = fs->blockSize() / 1024; @@ -239,25 +187 @@ void MountInfo::updateData() -//--------------------------------------------------------------------------- - -FileSystem::FileSystem( const QString &p ) - : fspath( p ), blkSize(512), totalBlks(0), availBlks(0) -{ - update(); -} - -void FileSystem::update() -{ -#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) - struct statfs fs; - if ( !statfs( fspath.latin1(), &fs ) ) { - blkSize = fs.f_bsize; - totalBlks = fs.f_blocks; - availBlks = fs.f_bavail; - } else { - blkSize = 0; - totalBlks = 0; - availBlks = 0; - } -#endif -} - 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; class QWidget; +class StorageInfo; -class StorageInfo : public QWidget +class FileSysInfo : public QWidget { @@ -38,3 +39,3 @@ class StorageInfo : public QWidget public: - StorageInfo( QWidget *parent=0, const char *name=0 ); + FileSysInfo( QWidget *parent=0, const char *name=0 ); @@ -45,6 +46,14 @@ private: void updateMounts(); - QDict<MountInfo> disks; - QList<QFrame> lines; + + QWidget *container; QVBoxLayout *vb; - QWidget *container; + + StorageInfo *storage; + QDict<MountInfo> disks; + QList<QFrame> lines; + + bool rebuildDisks; + +private slots: + void disksChanged(); }; @@ -55,3 +64,3 @@ class MountInfo : public QWidget public: - MountInfo( const QString &path, const QString &ttl, QWidget *parent=0, const char *name=0 ); + MountInfo( FileSystem *filesys=0, QWidget *parent=0, const char *name=0 ); ~MountInfo(); @@ -59,2 +68,4 @@ public: void updateData(); + + FileSystem *fs; @@ -62,3 +73,2 @@ private: QString title; - FileSystem *fs; QLabel *totalSize; @@ -69,21 +79 @@ private: -class FileSystem -{ -public: - FileSystem( const QString &p ); - - void update(); - - const QString &path() const { return fspath; } - long blockSize() const { return blkSize; } - long totalBlocks() const { return totalBlks; } - long availBlocks() const { return availBlks; } - -private: - QString fspath; - long blkSize; - long totalBlks; - long availBlks; -}; - - 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 ) #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) - tab->addTab( new StorageInfo( tab ), "sysinfo/storagetabicon", tr("Storage") ); + tab->addTab( new FileSysInfo( tab ), "sysinfo/storagetabicon", tr("Storage") ); #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 @@ #include <qpainter.h> +#include <qscrollview.h> #include <qtextstream.h> @@ -44,3 +45,11 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QVBoxLayout *vb = new QVBoxLayout( this, 4 ); + QVBoxLayout *tmpvb = new QVBoxLayout( this ); + QScrollView *sv = new QScrollView( this ); + tmpvb->addWidget( sv, 0, 0 ); + sv->setResizePolicy( QScrollView::AutoOneFit ); + sv->setFrameStyle( QFrame::NoFrame ); + QWidget *container = new QWidget( sv->viewport() ); + sv->addChild( container ); + + QVBoxLayout *vb = new QVBoxLayout( container, 4 ); @@ -80,3 +89,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *palmtopLogo = new QLabel( this ); + QLabel *palmtopLogo = new QLabel( container ); QImage logo1 = Resource::loadImage( "logo/opielogo" ); @@ -89,3 +98,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *palmtopVersion = new QLabel( this ); + QLabel *palmtopVersion = new QLabel( container ); palmtopVersion->setText( palmtopVersionString ); @@ -97,3 +106,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *linuxLogo = new QLabel( this ); + QLabel *linuxLogo = new QLabel( container ); QImage logo2 = Resource::loadImage( "logo/tux-logo" ); @@ -106,3 +115,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *kernelVersion = new QLabel( this ); + QLabel *kernelVersion = new QLabel( container ); kernelVersion->setText( kernelVersionString ); @@ -114,3 +123,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *palmtopLogo3 = new QLabel( this ); + QLabel *palmtopLogo3 = new QLabel( container ); QImage logo3 = Resource::loadImage( "sysinfo/pda" ); @@ -133,3 +142,3 @@ VersionInfo::VersionInfo( QWidget *parent, const char *name, WFlags f ) - QLabel *systemVersion = new QLabel( this ); + QLabel *systemVersion = new QLabel( container ); systemVersion->setText( systemString ); |