Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

storage.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 // additions copyright 2002 by L.J. Potter
00021 
00022 #include <qpe/storage.h>
00023 
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qscrollview.h>
00027 #include <qwhatsthis.h>
00028 
00029 #include "graph.h"
00030 #include "storage.h"
00031 
00032 #include <stdio.h>
00033  #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
00034 #include <sys/vfs.h>
00035 #include <mntent.h>
00036  #endif
00037 
00038 FileSysInfo::FileSysInfo( QWidget *parent, const char *name )
00039     : QWidget( parent, name )
00040 {
00041     QVBoxLayout *tmpvb = new QVBoxLayout( this );
00042     QScrollView *sv = new QScrollView( this );
00043     tmpvb->addWidget( sv, 0, 0 );
00044     sv->setResizePolicy( QScrollView::AutoOneFit );
00045     sv->setFrameStyle( QFrame::NoFrame );
00046     container = new QWidget( sv->viewport() );
00047     sv->addChild( container );
00048     vb = 0x0;
00049 
00050     storage = new StorageInfo( this );
00051     connect( storage, SIGNAL( disksChanged() ), this, SLOT( disksChanged() ) );
00052 
00053     lines.setAutoDelete(TRUE);
00054 
00055     rebuildDisks = TRUE;
00056     updateMounts();
00057     startTimer( 5000 );
00058 }
00059 
00060 
00061 void FileSysInfo::timerEvent(QTimerEvent*)
00062 {
00063     updateMounts();
00064 }
00065 
00066 void FileSysInfo::updateMounts()
00067 {
00068     storage->update();
00069 
00070     if ( rebuildDisks )
00071     {
00072         disks.clear();
00073         lines.clear();
00074 
00075         delete vb;
00076         vb = new QVBoxLayout( container/*, n > 3 ? 1 : 5*/ );
00077 
00078         bool frst=TRUE;
00079 
00080         FileSystem *fs;
00081         for ( QListIterator<FileSystem> it(storage->fileSystems()); it.current(); ++it )
00082         {
00083             fs = it.current();
00084 
00085             if(fs->disk().left(5) == "tmpfs")
00086             {
00087                 continue;
00088             }
00089 
00090             if ( !frst )
00091             {
00092                 QFrame *f = new QFrame( container );
00093                 vb->addWidget(f);
00094                 f->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00095                 lines.append(f);
00096                 f->show();
00097             }
00098             frst = FALSE;
00099 
00100             MountInfo *mi = new MountInfo( fs, container );
00101             vb->addWidget( mi );
00102             disks.insert( fs->path(), mi );
00103             mi->show();
00104             QString tempstr = fs->name().left( 2 );
00105             if ( tempstr == tr( "CF" ) )
00106                 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Compact Flash memory card." ) );
00107             else if ( tempstr == tr( "Ha" ) )
00108                 QWhatsThis::add( mi, tr( "This graph represents how much storage is currently used on this hard drive." ) );
00109             else if ( tempstr == tr( "SD" ) )
00110                 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used on this Secure Digital memory card." ) );
00111             else if ( tempstr == tr( "SC" ) )
00112                 QWhatsThis::add( mi, tr( "This graph represents how much storage is currently used on this hard drive." ) );
00113             else if ( tempstr == tr( "In" ) )
00114                 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." ) );
00115             else if ( tempstr == tr( "RA" ) )
00116                 QWhatsThis::add( mi, tr( "This graph represents how much memory is currently used of the temporary RAM disk." ) );
00117         }
00118         vb->addStretch();
00119     }
00120     else
00121     {
00122         for (QDictIterator<MountInfo> i(disks); i.current(); ++i)
00123             i.current()->updateData();
00124     }
00125 
00126     rebuildDisks = FALSE;
00127 }
00128 
00129 void FileSysInfo::disksChanged()
00130 {
00131     rebuildDisks = TRUE;
00132 }
00133 
00134 MountInfo::MountInfo( FileSystem *filesys, QWidget *parent, const char *name )
00135     : QWidget( parent, name )
00136 {
00137     QVBoxLayout *vb = new QVBoxLayout( this, 3 );
00138 
00139     totalSize = new QLabel( this );
00140     vb->addWidget( totalSize );
00141 
00142     fs = filesys;
00143     title = fs->name() + "\t (" + fs->path() + ')';
00144 
00145     data = new GraphData();
00146     graph = new BarGraph( this );
00147     graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00148     vb->addWidget( graph, 1 );
00149     graph->setData( data );
00150 
00151     legend = new GraphLegend( this );
00152     legend->setOrientation(Horizontal);
00153     vb->addWidget( legend );
00154     legend->setData( data );
00155 
00156     updateData();
00157 }
00158 
00159 MountInfo::~MountInfo()
00160 {
00161     delete data;
00162 }
00163 
00164 void MountInfo::updateData()
00165 {
00166     long mult = fs->blockSize() / 1024;
00167     long div = 1024 / fs->blockSize();
00168     if ( !mult ) mult = 1;
00169     if ( !div ) div = 1;
00170     long total = fs->totalBlocks() * mult / div;
00171     long avail = fs->availBlocks() * mult / div;
00172     long used = total - avail;
00173     totalSize->setText( title + tr(" : %1 kB").arg( total ) );
00174     data->clear();
00175     data->addItem( tr("Used (%1 kB)").arg(used), used );
00176     data->addItem( tr("Available (%1 kB)").arg(avail), avail );
00177     graph->repaint( FALSE );
00178     legend->update();
00179     graph->show();
00180     legend->show();
00181 }
00182 

Generated on Sat Nov 5 16:16:41 2005 for OPIE by  doxygen 1.4.2