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

0001 /*
0002     SPDX-FileCopyrightText: 1999 Michael Kropfberger <michael.kropfberger@gmx.net>
0003     SPDX-FileCopyrightText: 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef DISKLIST_H
0009 #define DISKLIST_H
0010 
0011 #include "disks.h"
0012 
0013 #include "kdfprivate_export.h"
0014 
0015 #include <KSharedConfig>
0016 
0017 // defines the os-type
0018 #include <qglobal.h>
0019 
0020 static QLatin1String DF_Command = QLatin1String( "df" );
0021 
0022 #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
0023     static QLatin1String DF_Args = QLatin1String( "-kT" );
0024     static const bool No_FS_Type = false;
0025 #else
0026     static QLatin1String DF_Args = QLatin1String( "-k" );
0027     static const bool No_FS_Type = true;
0028 #endif
0029 
0030 #if defined(Q_OS_SOLARIS)
0031     static QLatin1String CacheFSTAB = QLatin1String( "/etc/cachefstab" );
0032     static QLatin1String FSTAB = QLatin1String( "/etc/vfstab" );
0033 #else
0034     static QLatin1String FSTAB = QLatin1String( "/etc/fstab" );
0035 #endif
0036 
0037 static const QLatin1Char Separator = QLatin1Char( '|' );
0038 
0039 /***************************************************************************/
0040 typedef QList<DiskEntry*>                        Disks;
0041 typedef QList<DiskEntry*>::const_iterator        DisksConstIterator;
0042 typedef QList<DiskEntry*>::iterator              DisksIterator;
0043 
0044 class KProcess;
0045 
0046 class KDFPRIVATE_EXPORT DiskList : public QObject
0047 {
0048     Q_OBJECT
0049 
0050     public:
0051         explicit DiskList( QObject *parent=nullptr );
0052         ~DiskList() override;
0053 
0054         int readFSTAB();
0055         int readDF();
0056         int find(DiskEntry* disk);
0057         DiskEntry* at(int index) { return disks->at(index); }
0058         int count() const { return disks->count(); }
0059         void deleteAllMountedAt(const QString &mountpoint);
0060         void setUpdatesDisabled(bool disable);
0061 
0062         //To iterate over disks items
0063         DisksConstIterator disksConstIteratorBegin() { return disks->constBegin(); }
0064         DisksConstIterator disksConstIteratorEnd() { return disks->constEnd(); }
0065 
0066         DisksIterator disksIteratorBegin() { return disks->begin(); }
0067         DisksIterator disksIteratorEnd() { return disks->end(); }
0068 
0069     Q_SIGNALS:
0070         void readDFDone();
0071         void criticallyFull(DiskEntry *disk);
0072 
0073     public Q_SLOTS:
0074         void loadSettings();
0075         void applySettings();
0076 
0077     private Q_SLOTS:
0078         void dfDone();
0079 
0080     private:
0081         void replaceDeviceEntry(DiskEntry *disk);
0082 
0083         Disks  *disks;
0084         KProcess         *dfProc;
0085         bool              readingDFStdErrOut;
0086         KSharedConfigPtr  config;
0087         bool              updatesDisabled;
0088 
0089 };
0090 /***************************************************************************/
0091 
0092 
0093 #endif
0094