File indexing completed on 2024-05-19 16:31:38

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Dominik Haumann <dhaumann@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 #ifndef PLASMA_DISK_QUOTA_H
0007 #define PLASMA_DISK_QUOTA_H
0008 
0009 #include "QuotaListModel.h"
0010 #include <QObject>
0011 #include <QProcess>
0012 class QTimer;
0013 
0014 /**
0015  * Class monitoring the file system quota.
0016  * The monitoring is performed through a timer, running the 'quota'
0017  * command line tool.
0018  */
0019 class DiskQuota : public QObject
0020 {
0021     Q_OBJECT
0022 
0023     Q_PROPERTY(bool quotaInstalled READ quotaInstalled NOTIFY quotaInstalledChanged)
0024     Q_PROPERTY(bool cleanUpToolInstalled READ cleanUpToolInstalled NOTIFY cleanUpToolInstalledChanged)
0025 
0026     Q_PROPERTY(TrayStatus status READ status NOTIFY statusChanged)
0027     Q_PROPERTY(QString toolTip READ toolTip NOTIFY toolTipChanged)
0028     Q_PROPERTY(QString subToolTip READ subToolTip NOTIFY subToolTipChanged)
0029     Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged)
0030 
0031     Q_PROPERTY(QuotaListModel *model READ model CONSTANT)
0032 
0033 public:
0034     explicit DiskQuota(QObject *parent = nullptr);
0035 
0036 public:
0037     /**
0038      * System tray icon states.
0039      */
0040     enum TrayStatus {
0041         ActiveStatus = 0,
0042         PassiveStatus,
0043         NeedsAttentionStatus,
0044     };
0045     Q_ENUM(TrayStatus)
0046 
0047 public:
0048     bool quotaInstalled() const;
0049     void setQuotaInstalled(bool installed);
0050 
0051     bool cleanUpToolInstalled() const;
0052     void setCleanUpToolInstalled(bool installed);
0053 
0054     TrayStatus status() const;
0055     void setStatus(TrayStatus status);
0056 
0057     QString toolTip() const;
0058     void setToolTip(const QString &toolTip);
0059 
0060     QString subToolTip() const;
0061     void setSubToolTip(const QString &subToolTip);
0062 
0063     QString iconName() const;
0064     void setIconName(const QString &name);
0065 
0066     /**
0067      * Getter function for the model that is used in QML.
0068      */
0069     QuotaListModel *model() const;
0070 
0071 public Q_SLOTS:
0072     /**
0073      * Called every timer timeout to update the data model.
0074      * Launches an asynchronous 'quota' process to obtain data,
0075      * and finally calls quotaProcessFinished().
0076      */
0077     void updateQuota();
0078 
0079     /**
0080      * Processes the quota data from the 'quota' process.
0081      */
0082     void quotaProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
0083 
0084     /**
0085      * Opens the cleanup tool (filelight) at the folder @p mountPoint.
0086      */
0087     void openCleanUpTool(const QString &mountPoint);
0088 
0089 Q_SIGNALS:
0090     void quotaInstalledChanged();
0091     void cleanUpToolInstalledChanged();
0092     void statusChanged();
0093     void toolTipChanged();
0094     void subToolTipChanged();
0095     void iconNameChanged();
0096 
0097 private:
0098     QTimer *m_timer = nullptr;
0099     QProcess *m_quotaProcess = nullptr;
0100     bool m_quotaInstalled = true;
0101     bool m_cleanUpToolInstalled = true;
0102     TrayStatus m_status = PassiveStatus;
0103     QString m_iconName = QStringLiteral("disk-quota");
0104     QString m_toolTip;
0105     QString m_subToolTip;
0106     QuotaListModel *m_model = nullptr;
0107 };
0108 
0109 #endif // PLASMA_DISK_QUOTA_H