• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kdiskfreesp.cpp
1 /*
2  * kdiskfreesp.cpp
3  *
4  * Copyright (c) 1999 Michael Kropfberger <michael.kropfberger@gmx.net>
5  *
6  * Requires the Qt widget libraries, available at no cost at
7  * http://www.troll.no/
8  *
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License version 2 as published by the Free Software Foundation.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB. If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #include "kdiskfreesp.h"
26 #include <tqfile.h>
27 #include <tqtextstream.h>
28 
29 #include <kdebug.h>
30 #include <tdeprocess.h>
31 #include <tdeio/global.h>
32 #include <config-tdefile.h>
33 
34 #include "kdiskfreesp.moc"
35 
36 #define DF_COMMAND "df"
37 #define DF_ARGS "-k"
38 #define NO_FS_TYPE true
39 
40 #define BLANK ' '
41 #define FULL_PERCENT 95.0
42 
43 /***************************************************************************
44  * constructor
45 **/
46 KDiskFreeSp::KDiskFreeSp(TQObject *parent, const char *name)
47  : TQObject(parent,name)
48 {
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() ) );
55 
56  readingDFStdErrOut=false;
57 }
58 
59 
60 /***************************************************************************
61  * destructor
62 **/
63 KDiskFreeSp::~KDiskFreeSp()
64 {
65  delete dfProc;
66 }
67 
68 /***************************************************************************
69  * is called, when the df-command writes on StdOut
70 **/
71 void KDiskFreeSp::receivedDFStdErrOut(TDEProcess *, char *data, int len)
72 {
73  TQCString tmp(data,len+1); // adds a zero-byte
74  dfStringErrOut.append(tmp);
75 }
76 
77 /***************************************************************************
78  * reads the df-commands results
79 **/
80 int KDiskFreeSp::readDF( const TQString & mountPoint )
81 {
82  if (readingDFStdErrOut || dfProc->isRunning())
83  return -1;
84  m_mountPoint = mountPoint;
85  dfStringErrOut=""; // yet no data received
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;
90  return 1;
91 }
92 
93 
94 /***************************************************************************
95  * is called, when the df-command has finished
96 **/
97 void KDiskFreeSp::dfDone()
98 {
99  readingDFStdErrOut=true;
100 
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;
106  while ( !t.eof() ) {
107  TQString u,v;
108  s=t.readLine();
109  s=s.simplifyWhiteSpace();
110  if ( !s.isEmpty() ) {
111  //kdDebug(tdefile_area) << "GOT: [" << s << "]" << endl;
112 
113  if (s.find(BLANK)<0) // devicename was too long, rest in next line
114  if ( !t.eof() ) { // just appends the next line
115  v=t.readLine();
116  s=s.append(v);
117  s=s.simplifyWhiteSpace();
118  //kdDebug(tdefile_area) << "SPECIAL GOT: [" << s << "]" << endl;
119  }//if silly linefeed
120 
121  //kdDebug(tdefile_area) << "[" << s << "]" << endl;
122 
123  //TQString deviceName = s.left(s.find(BLANK));
124  s=s.remove(0,s.find(BLANK)+1 );
125  //kdDebug(tdefile_area) << " DeviceName: [" << deviceName << "]" << endl;
126 
127  if (!NO_FS_TYPE)
128  s=s.remove(0,s.find(BLANK)+1 ); // eat fs type
129 
130  u=s.left(s.find(BLANK));
131  unsigned long kBSize = u.toULong();
132  s=s.remove(0,s.find(BLANK)+1 );
133  //kdDebug(tdefile_area) << " Size: [" << kBSize << "]" << endl;
134 
135  u=s.left(s.find(BLANK));
136  unsigned long kBUsed = u.toULong();
137  s=s.remove(0,s.find(BLANK)+1 );
138  //kdDebug(tdefile_area) << " Used: [" << kBUsed << "]" << endl;
139 
140  u=s.left(s.find(BLANK));
141  unsigned long kBAvail = u.toULong();
142  s=s.remove(0,s.find(BLANK)+1 );
143  //kdDebug(tdefile_area) << " Avail: [" << kBAvail << "]" << endl;
144 
145 
146  s=s.remove(0,s.find(BLANK)+1 ); // delete the capacity 94%
147  TQString mountPoint = s.stripWhiteSpace();
148  //kdDebug(tdefile_area) << " MountPoint: [" << mountPoint << "]" << endl;
149 
150  if ( mountPoint == m_mountPoint )
151  {
152  //kdDebug(tdefile_area) << "Found mount point. Emitting" << endl;
153  emit foundMountPoint( mountPoint, kBSize, kBUsed, kBAvail );
154  emit foundMountPoint( kBSize, kBUsed, kBAvail, mountPoint ); // sic!
155  }
156  }//if not header
157  }//while further lines available
158 
159  readingDFStdErrOut=false;
160  emit done();
161  delete this;
162 }
163 
164 KDiskFreeSp * KDiskFreeSp::findUsageInfo( const TQString & path )
165 {
166  KDiskFreeSp * job = new KDiskFreeSp;
167  TQString mountPoint = TDEIO::findPathMountPoint( path );
168  job->readDF( mountPoint );
169  return job;
170 }
KDiskFreeSp
This class parses the output of "df" to find the disk usage information for a given partition (mount ...
Definition: kdiskfreesp.h:41
KDiskFreeSp::~KDiskFreeSp
~KDiskFreeSp()
Destructor - this object autodeletes itself when it's done.
Definition: kdiskfreesp.cpp:63
KDiskFreeSp::findUsageInfo
static KDiskFreeSp * findUsageInfo(const TQString &path)
Call this to fire a search on the disk usage information for the mount point containing path.
Definition: kdiskfreesp.cpp:164
KDiskFreeSp::readDF
int readDF(const TQString &mountPoint)
Call this to fire a search on the disk usage information for mountPoint.
Definition: kdiskfreesp.cpp:80

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.1
This website is maintained by Timothy Pearson.