| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "core/qmlitem.h" |
| 7 | #include "cpufreqprofilepart.h" |
| 8 | #include <QList> |
| 9 | #include <QObject> |
| 10 | #include <QString> |
| 11 | #include <optional> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | class CPUFreqQMLItem |
| 16 | : public QMLItem |
| 17 | , public CPUFreqProfilePart::Importer |
| 18 | , public CPUFreqProfilePart::Exporter |
| 19 | { |
| 20 | Q_OBJECT |
| 21 | |
| 22 | public: |
| 23 | explicit CPUFreqQMLItem() noexcept; |
| 24 | |
| 25 | signals: |
| 26 | void scalingGovernorChanged(QString const &governor); |
| 27 | void scalingGovernorsChanged(QList<QString> const &governors); |
| 28 | void eppHintChanged(QString const &hint); |
| 29 | void eppHintsChanged(QList<QString> const &hints); |
| 30 | void toggleEppHint(bool enable); |
| 31 | |
| 32 | public slots: |
| 33 | void changeScalingGovernor(QString const &governor); |
| 34 | void changeEPPHint(QString const &hint); |
| 35 | |
| 36 | public: |
| 37 | void activate(bool active) override; |
| 38 | |
| 39 | std::optional<std::reference_wrapper<Importable::Importer>> |
| 40 | provideImporter(Item const &i) override; |
| 41 | std::optional<std::reference_wrapper<Exportable::Exporter>> |
| 42 | provideExporter(Item const &i) override; |
| 43 | |
| 44 | bool provideActive() const override; |
| 45 | std::string const &provideCPUFreqScalingGovernor() const override; |
| 46 | std::optional<std::string> const &provideCPUFreqEPPHint() const override; |
| 47 | |
| 48 | void takeActive(bool active) override; |
| 49 | void takeCPUFreqScalingGovernor(std::string const &governor) override; |
| 50 | void takeCPUFreqEPPHint(std::optional<std::string> const &hint) override; |
| 51 | |
| 52 | std::unique_ptr<Exportable::Exporter> |
| 53 | initializer(IQMLComponentFactory const &qmlComponentFactory, |
| 54 | QQmlApplicationEngine &qmlEngine) override; |
| 55 | |
| 56 | private: |
| 57 | class Initializer; |
| 58 | void takeCPUFreqScalingGovernors(std::vector<std::string> const &governors); |
| 59 | void takeCPUFreqEPPHints(std::optional<std::vector<std::string>> const &hints); |
| 60 | |
| 61 | bool active_; |
| 62 | std::string scalingGovernor_; |
| 63 | std::string const eppScalingGovernor_{"powersave"}; |
| 64 | std::optional<std::string> eppHint_; |
| 65 | bool enableEpp_{false}; |
| 66 | |
| 67 | static bool register_(); |
| 68 | static bool const registered_; |
| 69 | |
| 70 | static char const *const trStrings[]; |
| 71 | }; |