File: ExternalServiceSettings.h

package info (click to toggle)
powerdevil 4%3A6.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,680 kB
  • sloc: cpp: 13,284; xml: 1,911; python: 1,204; sh: 19; makefile: 10
file content (89 lines) | stat: -rw-r--r-- 2,903 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 *  SPDX-FileCopyrightText: 2023 Jakob Petsovits <jpetso@petsovits.com>
 *  SPDX-FileCopyrightText: 2024 Fabian Arndt <fabian.arndt@root-core.net>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#pragma once

#include <KAuth/ExecuteJob>
#include <QObject>

class QWindow;

namespace PowerDevil
{

class ExternalServiceSettings : public QObject
{
    Q_OBJECT

    Q_PROPERTY(int chargeStartThreshold READ chargeStartThreshold WRITE setChargeStartThreshold NOTIFY chargeStartThresholdChanged)
    Q_PROPERTY(int chargeStopThreshold READ chargeStopThreshold WRITE setChargeStopThreshold NOTIFY chargeStopThresholdChanged)
    Q_PROPERTY(int batteryConservationMode READ batteryConservationMode WRITE setBatteryConservationMode NOTIFY batteryConservationModeChanged)

public:
    explicit ExternalServiceSettings(QObject *parent);

    bool isSaveNeeded() const;

    bool batteryConservationMode() const;
    int chargeStartThreshold() const;
    int chargeStopThreshold() const;

    bool isBatteryConservationModeSupported() const;
    bool isChargeStartThresholdSupported() const;
    bool isChargeStopThresholdSupported() const;

    bool chargeStopThresholdMightNeedReconnect() const;

public Q_SLOTS:
    void load(QWindow *parentWindowForKAuth = nullptr);
    void save(QWindow *parentWindowForKAuth = nullptr);

    void setBatteryConservationMode(bool);
    void setChargeStartThreshold(int);
    void setChargeStopThreshold(int);

Q_SIGNALS:
    void settingsChanged();

    // settings, which in addition to their own signal also trigger settingsChanged()
    void batteryConservationModeChanged();
    void chargeStartThresholdChanged();
    void chargeStopThresholdChanged();

    // not settings per se, so these don't trigger settingsChanged()
    void isBatteryConservationModeSupportedChanged();
    void isChargeStartThresholdSupportedChanged();
    void isChargeStopThresholdSupportedChanged();
    void chargeStopThresholdMightNeedReconnectChanged();

private:
    void setBatteryConservationModeSupported(bool);
    void setSavedBatteryConservationMode(bool);

    void setSavedChargeStartThreshold(int);
    void setSavedChargeStopThreshold(int);
    void setChargeStopThresholdMightNeedReconnect(bool);

    void executeChargeThresholdHelperAction(const QString &actionName,
                                            QWindow *parentWindowForKAuth,
                                            const QVariantMap &arguments,
                                            const std::function<void(KAuth::ExecuteJob *job)> callback);

    int m_chargeStartThreshold;
    int m_chargeStopThreshold;

    int m_savedChargeStartThreshold;
    int m_savedChargeStopThreshold;

    bool m_chargeStopThresholdMightNeedReconnect;

    bool m_isBatteryConservationModeSupported;
    bool m_batteryConservationMode;
    bool m_savedBatteryConservationMode;
};

} // namespace PowerDevil