File indexing completed on 2024-05-12 05:38:47

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 Jakob Petsovits <jpetso@petsovits.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 class QWindow;
0012 
0013 namespace PowerDevil
0014 {
0015 
0016 class ExternalServiceSettings : public QObject
0017 {
0018     Q_OBJECT
0019 
0020     Q_PROPERTY(int chargeStartThreshold READ chargeStartThreshold WRITE setChargeStartThreshold NOTIFY chargeStartThresholdChanged)
0021     Q_PROPERTY(int chargeStopThreshold READ chargeStopThreshold WRITE setChargeStopThreshold NOTIFY chargeStopThresholdChanged)
0022 
0023 public:
0024     explicit ExternalServiceSettings(QObject *parent);
0025 
0026     bool isSaveNeeded() const;
0027 
0028     int chargeStartThreshold() const;
0029     int chargeStopThreshold() const;
0030 
0031     bool isChargeStartThresholdSupported() const;
0032     bool isChargeStopThresholdSupported() const;
0033     bool chargeStopThresholdMightNeedReconnect() const;
0034 
0035 public Q_SLOTS:
0036     void load(QWindow *parentWindowForKAuth = nullptr);
0037     void save(QWindow *parentWindowForKAuth = nullptr);
0038 
0039     void setChargeStartThreshold(int);
0040     void setChargeStopThreshold(int);
0041 
0042 Q_SIGNALS:
0043     void settingsChanged();
0044 
0045     // settings, which in addition to their own signal also trigger settingsChanged()
0046     void chargeStartThresholdChanged();
0047     void chargeStopThresholdChanged();
0048 
0049     // not settings per se, so these don't trigger settingsChanged()
0050     void isChargeStartThresholdSupportedChanged();
0051     void isChargeStopThresholdSupportedChanged();
0052     void chargeStopThresholdMightNeedReconnectChanged();
0053 
0054 private:
0055     void setSavedChargeStartThreshold(int);
0056     void setSavedChargeStopThreshold(int);
0057     void setChargeStopThresholdMightNeedReconnect(bool);
0058 
0059     int m_chargeStartThreshold;
0060     int m_chargeStopThreshold;
0061     int m_savedChargeStartThreshold;
0062     int m_savedChargeStopThreshold;
0063     bool m_chargeStopThresholdMightNeedReconnect;
0064 };
0065 
0066 } // namespace PowerDevil