You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
5.3 KiB
170 lines
5.3 KiB
15 years ago
|
/*
|
||
|
* kdiskfreesp.cpp
|
||
|
*
|
||
|
* Copyright (c) 1999 Michael Kropfberger <michael.kropfberger@gmx.net>
|
||
|
*
|
||
|
* Requires the Qt widget libraries, available at no cost at
|
||
|
* http://www.troll.no/
|
||
|
*
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License version 2 as published by the Free Software Foundation.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kdiskfreesp.h"
|
||
15 years ago
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtextstream.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kprocess.h>
|
||
12 years ago
|
#include <tdeio/global.h>
|
||
|
#include <config-tdefile.h>
|
||
15 years ago
|
|
||
|
#include "kdiskfreesp.moc"
|
||
|
|
||
|
#define DF_COMMAND "df"
|
||
|
#define DF_ARGS "-k"
|
||
|
#define NO_FS_TYPE true
|
||
|
|
||
|
#define BLANK ' '
|
||
|
#define FULL_PERCENT 95.0
|
||
|
|
||
|
/***************************************************************************
|
||
|
* constructor
|
||
|
**/
|
||
15 years ago
|
KDiskFreeSp::KDiskFreeSp(TQObject *parent, const char *name)
|
||
|
: TQObject(parent,name)
|
||
15 years ago
|
{
|
||
12 years ago
|
dfProc = new TDEProcess(); TQ_CHECK_PTR(dfProc);
|
||
15 years ago
|
dfProc->setEnvironment("LANGUAGE", "C");
|
||
12 years ago
|
connect( dfProc, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int) ),
|
||
|
this, TQT_SLOT (receivedDFStdErrOut(TDEProcess *, char *, int)) );
|
||
|
connect(dfProc,TQT_SIGNAL(processExited(TDEProcess *) ),
|
||
15 years ago
|
this, TQT_SLOT(dfDone() ) );
|
||
15 years ago
|
|
||
|
readingDFStdErrOut=false;
|
||
|
}
|
||
|
|
||
|
|
||
|
/***************************************************************************
|
||
|
* destructor
|
||
|
**/
|
||
|
KDiskFreeSp::~KDiskFreeSp()
|
||
|
{
|
||
|
delete dfProc;
|
||
|
}
|
||
|
|
||
|
/***************************************************************************
|
||
|
* is called, when the df-command writes on StdOut
|
||
|
**/
|
||
12 years ago
|
void KDiskFreeSp::receivedDFStdErrOut(TDEProcess *, char *data, int len)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString tmp(data,len+1); // adds a zero-byte
|
||
15 years ago
|
dfStringErrOut.append(tmp);
|
||
|
}
|
||
|
|
||
|
/***************************************************************************
|
||
|
* reads the df-commands results
|
||
|
**/
|
||
15 years ago
|
int KDiskFreeSp::readDF( const TQString & mountPoint )
|
||
15 years ago
|
{
|
||
|
if (readingDFStdErrOut || dfProc->isRunning())
|
||
|
return -1;
|
||
|
m_mountPoint = mountPoint;
|
||
|
dfStringErrOut=""; // yet no data received
|
||
|
dfProc->clearArguments();
|
||
15 years ago
|
(*dfProc) << TQString::fromLocal8Bit(DF_COMMAND) << TQString::fromLocal8Bit(DF_ARGS);
|
||
12 years ago
|
if (!dfProc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput ))
|
||
15 years ago
|
kdError() << "could not execute ["<< DF_COMMAND << "]" << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
/***************************************************************************
|
||
|
* is called, when the df-command has finished
|
||
|
**/
|
||
|
void KDiskFreeSp::dfDone()
|
||
|
{
|
||
|
readingDFStdErrOut=true;
|
||
|
|
||
15 years ago
|
TQTextStream t (dfStringErrOut, IO_ReadOnly);
|
||
|
TQString s=t.readLine();
|
||
13 years ago
|
if ( (s.isEmpty()) || ( s.left(10) != TQString::fromLatin1("Filesystem") ) )
|
||
15 years ago
|
kdError() << "Error running df command... got [" << s << "]" << endl;
|
||
|
while ( !t.eof() ) {
|
||
15 years ago
|
TQString u,v;
|
||
15 years ago
|
s=t.readLine();
|
||
|
s=s.simplifyWhiteSpace();
|
||
|
if ( !s.isEmpty() ) {
|
||
12 years ago
|
//kdDebug(tdefile_area) << "GOT: [" << s << "]" << endl;
|
||
15 years ago
|
|
||
13 years ago
|
if (s.find(BLANK)<0) // devicename was too long, rest in next line
|
||
15 years ago
|
if ( !t.eof() ) { // just appends the next line
|
||
|
v=t.readLine();
|
||
|
s=s.append(v);
|
||
|
s=s.simplifyWhiteSpace();
|
||
12 years ago
|
//kdDebug(tdefile_area) << "SPECIAL GOT: [" << s << "]" << endl;
|
||
15 years ago
|
}//if silly linefeed
|
||
|
|
||
12 years ago
|
//kdDebug(tdefile_area) << "[" << s << "]" << endl;
|
||
15 years ago
|
|
||
13 years ago
|
//TQString deviceName = s.left(s.find(BLANK));
|
||
|
s=s.remove(0,s.find(BLANK)+1 );
|
||
12 years ago
|
//kdDebug(tdefile_area) << " DeviceName: [" << deviceName << "]" << endl;
|
||
15 years ago
|
|
||
|
if (!NO_FS_TYPE)
|
||
13 years ago
|
s=s.remove(0,s.find(BLANK)+1 ); // eat fs type
|
||
15 years ago
|
|
||
13 years ago
|
u=s.left(s.find(BLANK));
|
||
15 years ago
|
unsigned long kBSize = u.toULong();
|
||
13 years ago
|
s=s.remove(0,s.find(BLANK)+1 );
|
||
12 years ago
|
//kdDebug(tdefile_area) << " Size: [" << kBSize << "]" << endl;
|
||
15 years ago
|
|
||
13 years ago
|
u=s.left(s.find(BLANK));
|
||
15 years ago
|
unsigned long kBUsed = u.toULong();
|
||
13 years ago
|
s=s.remove(0,s.find(BLANK)+1 );
|
||
12 years ago
|
//kdDebug(tdefile_area) << " Used: [" << kBUsed << "]" << endl;
|
||
15 years ago
|
|
||
13 years ago
|
u=s.left(s.find(BLANK));
|
||
15 years ago
|
unsigned long kBAvail = u.toULong();
|
||
13 years ago
|
s=s.remove(0,s.find(BLANK)+1 );
|
||
12 years ago
|
//kdDebug(tdefile_area) << " Avail: [" << kBAvail << "]" << endl;
|
||
15 years ago
|
|
||
|
|
||
13 years ago
|
s=s.remove(0,s.find(BLANK)+1 ); // delete the capacity 94%
|
||
15 years ago
|
TQString mountPoint = s.stripWhiteSpace();
|
||
12 years ago
|
//kdDebug(tdefile_area) << " MountPoint: [" << mountPoint << "]" << endl;
|
||
15 years ago
|
|
||
|
if ( mountPoint == m_mountPoint )
|
||
|
{
|
||
12 years ago
|
//kdDebug(tdefile_area) << "Found mount point. Emitting" << endl;
|
||
15 years ago
|
emit foundMountPoint( mountPoint, kBSize, kBUsed, kBAvail );
|
||
|
emit foundMountPoint( kBSize, kBUsed, kBAvail, mountPoint ); // sic!
|
||
|
}
|
||
|
}//if not header
|
||
|
}//while further lines available
|
||
|
|
||
|
readingDFStdErrOut=false;
|
||
|
emit done();
|
||
|
delete this;
|
||
|
}
|
||
|
|
||
14 years ago
|
KDiskFreeSp * KDiskFreeSp::findUsageInfo( const TQString & path )
|
||
15 years ago
|
{
|
||
|
KDiskFreeSp * job = new KDiskFreeSp;
|
||
12 years ago
|
TQString mountPoint = TDEIO::findPathMountPoint( path );
|
||
15 years ago
|
job->readDF( mountPoint );
|
||
|
return job;
|
||
|
}
|