File indexing completed on 2024-04-21 05:50:16

0001 /*
0002     SPDX-FileCopyrightText: 1998 Michael Kropfberger <michael.kropfberger@gmx.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef DISKS_H
0007 #define DISKS_H
0008 
0009 #include "kdfprivate_export.h"
0010 
0011 #include <kio/global.h>
0012 
0013 #include <QObject>
0014 
0015 class KProcess;
0016 
0017 class KDFPRIVATE_EXPORT DiskEntry : public QObject
0018 {
0019     Q_OBJECT
0020 
0021     public:
0022         explicit DiskEntry(QObject *parent=nullptr, const QString &name=QString());
0023         explicit DiskEntry(const QString & deviceName, QObject *parent=nullptr, const QString &name=QString());
0024         ~DiskEntry() override;
0025         QString lastSysError() {return sysStringErrOut; }
0026         QString deviceName() const { return device; }
0027         // The real device (in case deviceName() is a symlink)
0028         QString deviceRealName() const;
0029         QString mountPoint() const { return mountedOn; }
0030         QString mountOptions() const { return options; }
0031         // The real device (in case deviceName() is a symlink)
0032         QString realMountPoint() const;
0033         /**
0034         * sets the used mountCommand for the actual DiskEntry.
0035         * @return mntcmd   is a string containing the executable file and
0036         *                 special codes which will be filled in when used: <BR>
0037         *                 %m : mountpoint <BR>
0038         *                 %d : deviceName <BR>
0039         *                 %t : filesystem type <BR>
0040         *                 %o : mount options <BR>
0041         *                 all this information is gained from the objects' data
0042         *                 if no mountCommand is set it defaults to "mount %d"
0043         **/
0044         QString mountCommand() const { return mntcmd; }
0045         /**
0046         * sets the used umountCommand for the actual DiskEntry.
0047         * @return umntcmd   is a string containing the executable file and
0048         *                 special codes which will be filled in when used: <BR>
0049         *                 %m : mountpoint <BR>
0050         *                 %d : deviceName <BR>
0051         *                 all this information is gained from the objects' data
0052         *                 if no umountCommand is set it defaults to "umount %d"
0053         **/
0054         QString umountCommand() const { return umntcmd; }
0055         QString fsType() const { return type; }
0056         bool mounted() const { return isMounted; }
0057         qulonglong kBSize() const { return size; }
0058         QString iconName();
0059         QString realIconName() { return icoName; }
0060         QString prettyKBSize() const { return KIO::convertSizeFromKiB(size); }
0061         qulonglong kBUsed() const { return used; }
0062         QString prettyKBUsed() const { return KIO::convertSizeFromKiB(used); }
0063         qulonglong kBAvail() const  { return avail; }
0064         QString prettyKBAvail() const { return KIO::convertSizeFromKiB(avail); }
0065         int percentFull() const;
0066         // == comparison
0067         bool operator==( const DiskEntry & s2 ) const
0068         {
0069             bool ret = this->deviceName() == s2.deviceName();
0070             if( ret )
0071                 ret = this->mountPoint()  == s2.mountPoint();
0072 
0073             return( ret );
0074         }
0075         // Comparison using *real* device and mountpoint
0076         bool realCompare( const DiskEntry & s2 ) const
0077         {
0078             bool ret = this->deviceRealName() == s2.deviceRealName();
0079             if( ret )
0080                 ret = this->realMountPoint()  == s2.realMountPoint();
0081 
0082             return( ret );
0083         }
0084 
0085     Q_SIGNALS:
0086         void sysCallError(DiskEntry *disk, int err_no);
0087         void deviceNameChanged();
0088         void mountPointChanged();
0089         void mountOptionsChanged();
0090         void fsTypeChanged();
0091         void mountedChanged();
0092         void kBSizeChanged();
0093         void kBUsedChanged();
0094         void kBAvailChanged();
0095         void iconNameChanged();
0096 
0097     public Q_SLOTS:
0098         int toggleMount();
0099         int mount();
0100         int umount();
0101         int remount();
0102         void setMountCommand(const QString & mnt);
0103         void setUmountCommand(const QString & umnt);
0104         void setDeviceName(const QString & deviceName);
0105         void setMountPoint(const QString & mountPoint);
0106         void setIconName(const QString & iconName);
0107         void setIconToDefault();
0108         void setMountOptions(const QString & mountOptions);
0109         void setFsType(const QString & fsType);
0110         void setMounted(bool nowMounted);
0111         void setKBSize(qulonglong kb_size);
0112         void setKBUsed(qulonglong kb_used);
0113         void setKBAvail(qulonglong kb_avail);
0114         QString guessIconName();
0115 
0116     private Q_SLOTS:
0117         void receivedSysStdErrOut();
0118 
0119     private:
0120         void init(const QString &name);
0121         int sysCall(QString & command);
0122 
0123         KProcess     *sysProc;
0124         QString           sysStringErrOut;
0125         bool              readingSysStdErrOut;
0126 
0127         QString     device,
0128         type,
0129         mountedOn,
0130         options,
0131         icoName,
0132         mntcmd,
0133         umntcmd;
0134 
0135         qulonglong  size,
0136         used,
0137         avail;       // ATTENTION: used+avail != size (clustersize!)
0138 
0139         bool        isMounted,
0140         iconSetByUser;
0141 };
0142 
0143 #endif
0144