25 #include "kdiskfreesp.h"
27 #include <tqtextstream.h>
30 #include <tdeprocess.h>
31 #include <tdeio/global.h>
32 #include <config-tdefile.h>
34 #include "kdiskfreesp.moc"
36 #define DF_COMMAND "df"
38 #define NO_FS_TYPE true
41 #define FULL_PERCENT 95.0
46 KDiskFreeSp::KDiskFreeSp(TQObject *parent,
const char *name)
47 : TQObject(parent,name)
49 dfProc =
new TDEProcess(); TQ_CHECK_PTR(dfProc);
50 dfProc->setEnvironment(
"LANGUAGE",
"C");
51 connect( dfProc, TQ_SIGNAL(receivedStdout(TDEProcess *,
char *,
int) ),
52 this, TQ_SLOT (receivedDFStdErrOut(TDEProcess *,
char *,
int)) );
53 connect(dfProc,TQ_SIGNAL(processExited(TDEProcess *) ),
54 this, TQ_SLOT(dfDone() ) );
56 readingDFStdErrOut=
false;
71 void KDiskFreeSp::receivedDFStdErrOut(TDEProcess *,
char *data,
int len)
73 TQCString tmp(data,len+1);
74 dfStringErrOut.append(tmp);
82 if (readingDFStdErrOut || dfProc->isRunning())
84 m_mountPoint = mountPoint;
86 dfProc->clearArguments();
87 (*dfProc) << TQString::fromLocal8Bit(DF_COMMAND) << TQString::fromLocal8Bit(DF_ARGS);
88 if (!dfProc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput ))
89 kdError() <<
"could not execute ["<< DF_COMMAND <<
"]" << endl;
97 void KDiskFreeSp::dfDone()
99 readingDFStdErrOut=
true;
101 TQTextStream t (dfStringErrOut, IO_ReadOnly);
102 t.setEncoding(TQTextStream::Locale);
103 TQString s=t.readLine();
104 if ( (s.isEmpty()) || ( s.left(10) != TQString::fromLatin1(
"Filesystem") ) )
105 kdError() <<
"Error running df command... got [" << s <<
"]" << endl;
109 s=s.simplifyWhiteSpace();
110 if ( !s.isEmpty() ) {
117 s=s.simplifyWhiteSpace();
124 s=s.remove(0,s.find(BLANK)+1 );
128 s=s.remove(0,s.find(BLANK)+1 );
130 u=s.left(s.find(BLANK));
131 unsigned long kBSize = u.toULong();
132 s=s.remove(0,s.find(BLANK)+1 );
135 u=s.left(s.find(BLANK));
136 unsigned long kBUsed = u.toULong();
137 s=s.remove(0,s.find(BLANK)+1 );
140 u=s.left(s.find(BLANK));
141 unsigned long kBAvail = u.toULong();
142 s=s.remove(0,s.find(BLANK)+1 );
146 s=s.remove(0,s.find(BLANK)+1 );
147 TQString mountPoint = s.stripWhiteSpace();
150 if ( mountPoint == m_mountPoint )
153 emit foundMountPoint( mountPoint, kBSize, kBUsed, kBAvail );
154 emit foundMountPoint( kBSize, kBUsed, kBAvail, mountPoint );
159 readingDFStdErrOut=
false;
167 TQString mountPoint = TDEIO::findPathMountPoint( path );
168 job->
readDF( mountPoint );
This class parses the output of "df" to find the disk usage information for a given partition (mount ...
~KDiskFreeSp()
Destructor - this object autodeletes itself when it's done.
static KDiskFreeSp * findUsageInfo(const TQString &path)
Call this to fire a search on the disk usage information for the mount point containing path.
int readDF(const TQString &mountPoint)
Call this to fire a search on the disk usage information for mountPoint.