• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kfile
 

kio/kfile

  • kio
  • kfile
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 <kprocess.h>
31 #include <kio/global.h>
32 #include <config-kfile.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 KProcess(); Q_CHECK_PTR(dfProc);
50  dfProc->setEnvironment("LANGUAGE", "C");
51  connect( dfProc, TQT_SIGNAL(receivedStdout(KProcess *, char *, int) ),
52  this, TQT_SLOT (receivedDFStdErrOut(KProcess *, char *, int)) );
53  connect(dfProc,TQT_SIGNAL(processExited(KProcess *) ),
54  this, TQT_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(KProcess *, 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( KProcess::NotifyOnExit, KProcess::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  TQString s=t.readLine();
103  if ( (s.isEmpty()) || ( s.left(10) != TQString::fromLatin1("Filesystem") ) )
104  kdError() << "Error running df command... got [" << s << "]" << endl;
105  while ( !t.eof() ) {
106  TQString u,v;
107  s=t.readLine();
108  s=s.simplifyWhiteSpace();
109  if ( !s.isEmpty() ) {
110  //kdDebug(kfile_area) << "GOT: [" << s << "]" << endl;
111 
112  if (s.find(BLANK)<0) // devicename was too long, rest in next line
113  if ( !t.eof() ) { // just appends the next line
114  v=t.readLine();
115  s=s.append(v);
116  s=s.simplifyWhiteSpace();
117  //kdDebug(kfile_area) << "SPECIAL GOT: [" << s << "]" << endl;
118  }//if silly linefeed
119 
120  //kdDebug(kfile_area) << "[" << s << "]" << endl;
121 
122  //TQString deviceName = s.left(s.find(BLANK));
123  s=s.remove(0,s.find(BLANK)+1 );
124  //kdDebug(kfile_area) << " DeviceName: [" << deviceName << "]" << endl;
125 
126  if (!NO_FS_TYPE)
127  s=s.remove(0,s.find(BLANK)+1 ); // eat fs type
128 
129  u=s.left(s.find(BLANK));
130  unsigned long kBSize = u.toULong();
131  s=s.remove(0,s.find(BLANK)+1 );
132  //kdDebug(kfile_area) << " Size: [" << kBSize << "]" << endl;
133 
134  u=s.left(s.find(BLANK));
135  unsigned long kBUsed = u.toULong();
136  s=s.remove(0,s.find(BLANK)+1 );
137  //kdDebug(kfile_area) << " Used: [" << kBUsed << "]" << endl;
138 
139  u=s.left(s.find(BLANK));
140  unsigned long kBAvail = u.toULong();
141  s=s.remove(0,s.find(BLANK)+1 );
142  //kdDebug(kfile_area) << " Avail: [" << kBAvail << "]" << endl;
143 
144 
145  s=s.remove(0,s.find(BLANK)+1 ); // delete the capacity 94%
146  TQString mountPoint = s.stripWhiteSpace();
147  //kdDebug(kfile_area) << " MountPoint: [" << mountPoint << "]" << endl;
148 
149  if ( mountPoint == m_mountPoint )
150  {
151  //kdDebug(kfile_area) << "Found mount point. Emitting" << endl;
152  emit foundMountPoint( mountPoint, kBSize, kBUsed, kBAvail );
153  emit foundMountPoint( kBSize, kBUsed, kBAvail, mountPoint ); // sic!
154  }
155  }//if not header
156  }//while further lines available
157 
158  readingDFStdErrOut=false;
159  emit done();
160  delete this;
161 }
162 
163 KDiskFreeSp * KDiskFreeSp::findUsageInfo( const TQString & path )
164 {
165  KDiskFreeSp * job = new KDiskFreeSp;
166  TQString mountPoint = KIO::findPathMountPoint( path );
167  job->readDF( mountPoint );
168  return job;
169 }

kio/kfile

Skip menu "kio/kfile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/kfile

Skip menu "kio/kfile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kfile by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |