1/*
2* disks.h
3*
4* Copyright (c) 1998 Michael Kropfberger <michael.kropfberger@gmx.net>
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21#ifndef DISKS_H
22#define DISKS_H
23
24#include <QtCore/QObject>
25
26#include <kio/global.h>
27
28class KProcess;
29
30class DiskEntry : public QObject
31{
32 Q_OBJECT
33
34 public:
35 explicit DiskEntry(QObject *parent=0, const char *name=0);
36 explicit DiskEntry(const QString & deviceName, QObject *parent=0, const char *name=0);
37 ~DiskEntry();
38 QString lastSysError() {return sysStringErrOut; }
39 QString deviceName() const { return device; }
40 // The real device (in case deviceName() is a symlink)
41 QString deviceRealName() const;
42 QString mountPoint() const { return mountedOn; }
43 QString mountOptions() const { return options; }
44 // The real device (in case deviceName() is a symlink)
45 QString realMountPoint() const;
46 /**
47 * sets the used mountCommand for the actual DiskEntry.
48 * @param mntcmd is a string containing the executable file and
49 * special codes which will be filled in when used: <BR>
50 * %m : mountpoint <BR>
51 * %d : deviceName <BR>
52 * %t : filesystem type <BR>
53 * %o : mount options <BR>
54 * all this information is gained from the objects' data
55 * if no mountCommand is set it defaults to "mount %d"
56 **/
57 QString mountCommand() const { return mntcmd; }
58 /**
59 * sets the used umountCommand for the actual DiskEntry.
60 * @param mntcmd is a string containing the executable file and
61 * special codes which will be filled in when used: <BR>
62 * %m : mountpoint <BR>
63 * %d : deviceName <BR>
64 * all this information is gained from the objects' data
65 * if no umountCommand is set it defaults to "umount %d"
66 **/
67 QString umountCommand() const { return umntcmd; }
68 QString fsType() const { return type; }
69 bool mounted() const { return isMounted; }
70 qulonglong kBSize() const { return size; }
71 QString iconName();
72 QString realIconName() { return icoName; }
73 QString prettyKBSize() const { return KIO::convertSizeFromKiB(size); }
74 qulonglong kBUsed() const { return used; }
75 QString prettyKBUsed() const { return KIO::convertSizeFromKiB(used); }
76 qulonglong kBAvail() const { return avail; }
77 QString prettyKBAvail() const { return KIO::convertSizeFromKiB(avail); }
78 float percentFull() const;
79 // == comparison
80 bool operator==( const DiskEntry & s2 ) const
81 {
82 bool ret = this->deviceName() == s2.deviceName();
83 if( ret )
84 ret = this->mountPoint() == s2.mountPoint();
85
86 return( ret );
87 }
88 // Comparison using *real* device and mountpoint
89 bool realCompare( const DiskEntry & s2 ) const
90 {
91 bool ret = this->deviceRealName() == s2.deviceRealName();
92 if( ret )
93 ret = this->realMountPoint() == s2.realMountPoint();
94
95 return( ret );
96 }
97
98 Q_SIGNALS:
99 void sysCallError(DiskEntry *disk, int err_no);
100 void deviceNameChanged();
101 void mountPointChanged();
102 void mountOptionsChanged();
103 void fsTypeChanged();
104 void mountedChanged();
105 void kBSizeChanged();
106 void kBUsedChanged();
107 void kBAvailChanged();
108 void iconNameChanged();
109
110 public Q_SLOTS:
111 int toggleMount();
112 int mount();
113 int umount();
114 int remount();
115 void setMountCommand(const QString & mnt);
116 void setUmountCommand(const QString & umnt);
117 void setDeviceName(const QString & deviceName);
118 void setMountPoint(const QString & mountPoint);
119 void setIconName(const QString & iconName);
120 void setIconToDefault();
121 void setMountOptions(const QString & mountOptions);
122 void setFsType(const QString & fsType);
123 void setMounted(bool nowMounted);
124 void setKBSize(qulonglong kb_size);
125 void setKBUsed(qulonglong kb_used);
126 void setKBAvail(qulonglong kb_avail);
127 QString guessIconName();
128
129 private slots:
130 void receivedSysStdErrOut();
131
132 private:
133 void init(const char *name);
134 int sysCall(QString & command);
135 QString prettyPrint(int kBValue) const;
136
137 KProcess *sysProc;
138 QString sysStringErrOut;
139 bool readingSysStdErrOut;
140
141 QString device,
142 type,
143 mountedOn,
144 options,
145 icoName,
146 mntcmd,
147 umntcmd;
148
149 qulonglong size,
150 used,
151 avail; // ATTENTION: used+avail != size (clustersize!)
152
153 bool isMounted,
154 iconSetByUser;
155};
156
157#endif
158
159