File indexing completed on 2024-04-21 16:30:37

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2017 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef _SysLoad_H_
0022 #define _SysLoad_H_
0023 
0024 #include <QFrame>
0025 #include <QVector>
0026 #include <QMap>
0027 #include <QByteArray>
0028 #include <QTimer>
0029 
0030 class SysLoad : public QFrame
0031 {
0032   Q_OBJECT
0033 
0034   Q_PROPERTY(QColor cpuUserColor   MEMBER cpuUserColor)
0035   Q_PROPERTY(QColor cpuSystemColor MEMBER cpuSystemColor)
0036   Q_PROPERTY(QColor cpuNiceColor   MEMBER cpuNiceColor)
0037   Q_PROPERTY(bool   cpuSummaryBar  MEMBER cpuSummaryBar)
0038 
0039   Q_PROPERTY(QColor memUsedColor   MEMBER memUsedColor)
0040   Q_PROPERTY(QColor memCachedColor MEMBER memCachedColor)
0041   Q_PROPERTY(QColor memSwapColor   MEMBER memSwapColor)
0042 
0043   Q_PROPERTY(QColor netReceivedColor MEMBER netReceivedColor)
0044   Q_PROPERTY(QColor netSentColor     MEMBER netSentColor)
0045 
0046   public:
0047     SysLoad(QWidget *parent);
0048 
0049   protected:
0050     void paintEvent(QPaintEvent *event) override;
0051     void mousePressEvent(QMouseEvent *event) override;
0052 
0053   private Q_SLOTS:
0054     void fetch();
0055 
0056   private:
0057     struct CpuData
0058     {
0059       int userCPU = 0, niceCPU = 0, systemCPU = 0;
0060       double userPercent = 0, nicePercent = 0, systemPercent = 0;
0061       double MHz = 0;
0062     };
0063 
0064     struct MemoryData
0065     {
0066       double memPercent = 0;
0067       double memCachedPercent = 0;
0068       double swapPercent = 0;
0069     } memData;
0070 
0071     struct NetworkData
0072     {
0073       size_t prevReceived = 0, prevSent = 0;
0074       size_t received = 0, sent = 0;
0075       bool valid = false;
0076     };
0077 
0078     QVector<CpuData> cpus;
0079 
0080     QMap<QByteArray, NetworkData> netDevs;
0081     size_t maxScale = 0;
0082     size_t maxBytes = 0;
0083     size_t sumSent = 0, sumReceived = 0;
0084 
0085     QTimer timeoutTimer;
0086     QTimer netLoadTimer;
0087 
0088     QColor cpuUserColor   = "#881f1f";
0089     QColor cpuSystemColor = Qt::darkGreen;
0090     QColor cpuNiceColor   = Qt::yellow;
0091     bool cpuSummaryBar    = false;
0092 
0093     QColor memUsedColor   = Qt::blue;
0094     QColor memCachedColor = Qt::darkGreen;
0095     QColor memSwapColor   = Qt::cyan;
0096 
0097     QColor netReceivedColor = Qt::green;
0098     QColor netSentColor     = Qt::red;
0099 };
0100 
0101 #endif