summaryrefslogtreecommitdiffstats
path: root/kdf/disklist.h
blob: 638dc5934275ccee7f6a6da16560b4576eec27e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * disklist.h
 *
 * Copyright (c) 1999 Michael Kropfberger <michael.kropfberger@gmx.net>
 *
 * Requires the TQt widget libraries, available at no cost at
 * http://www.troll.no/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#ifndef __DISKLIST_H__
#define __DISKLIST_H__

#include <kdebug.h>
#include <kconfig.h>
#include <klocale.h>
//#include <kcontrol.h>

// defines the os-type
#include <tqglobal.h>

#include "disks.h"

#define DF_COMMAND    "df"
// be pessimistic: df -T only works under linux !??
#if defined(_OS_LINUX_)
#define DF_ARGS       "-kT"
#define NO_FS_TYPE    false
#else
#define DF_ARGS       "-k"
#define NO_FS_TYPE    true
#endif

#ifdef _OS_SOLARIS_
#define CACHEFSTAB "/etc/cachefstab"
#define FSTAB "/etc/vfstab"
#else
#define FSTAB "/etc/fstab"
#endif

#define SEPARATOR "|"

/***************************************************************************/
typedef TQPtrList<DiskEntry>		DisksBase;
typedef TQPtrListIterator<DiskEntry>	DisksIterator;

/***************************************************************************/
class Disks : public DisksBase
{
 public:
  Disks(bool deepCopies=TRUE) { dc = deepCopies;}
  ~Disks() { clear(); }
private:
  int compareItems( DiskEntry s1, DiskEntry s2 )
  {
    int ret = s1.deviceName().compare(s2.deviceName());
    if( ret == 0 )
    {
      ret = s1.mountPoint().compare(s2.mountPoint());
    }

    kdDebug() << "compareDISKS " << s1.deviceName() << " vs " << s2.deviceName() << " (" << ret << ")" << endl;
    return( ret );
  }

  /*
  int compareItems( DiskEntry* s1, DiskEntry* s2 ) {
	int ret;
	ret = strcmp (static_cast<DiskEntry*>(s1)->deviceName(),
		      static_cast<DiskEntry*>(s2)->deviceName() );
	if (0 == ret)
	   ret = strcmp (static_cast<DiskEntry*>(s1)->mountPoint(),
			 static_cast<DiskEntry*>(s2)->mountPoint());
	return ret;
      };
  */

  bool  dc;
};

/***************************************************************************/
class DiskList : public TQObject
{  Q_OBJECT
  TQ_OBJECT
public:
   DiskList( TQObject *tqparent=0, const char *name=0 );
 ~DiskList();
   int readFSTAB();
   int readDF();
   int find(const DiskEntry* disk) {return disks->find(disk);}
   DiskEntry*  at(uint index) {return disks->at(index);}
   DiskEntry* first() {return disks->first();}
   DiskEntry* next() {return disks->next();}
   uint count() { return disks->count(); }

   void deleteAllMountedAt(const TQString &mountpoint);
   void setUpdatesDisabled(bool disable);
   
signals:
   void readDFDone();
   void criticallyFull(DiskEntry *disk);

public slots:
  void loadSettings();
  void applySettings();

private slots:
   void receivedDFStdErrOut(KProcess *, char *data, int len);
   void dfDone();

private:
  void replaceDeviceEntry(DiskEntry *disk);

  Disks            *disks;
  KProcess         *dfProc;
  TQString           dfStringErrOut;
  bool              readingDFStdErrOut;
  KConfig           *config;
  bool              updatesDisabled;
  
};
/***************************************************************************/


#endif