harbour-batterybuddy/src/battery.h

76 lines
2.2 KiB
C
Raw Normal View History

2019-01-05 18:14:00 +03:00
#ifndef BATTERY_H
#define BATTERY_H
/**
* Battery Buddy, a Sailfish application to prolong battery lifetime
*
* Copyright (C) 2019 Matti Viljanen
*
* Battery Buddy is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Battery Buddy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details. You should have received a copy of the GNU
* General Public License along with CarBudget. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Matti Viljanen
*/
#include <QObject>
2019-01-05 18:14:00 +03:00
#include <QString>
#include <QFile>
class Battery : public QObject
{
Q_OBJECT
Q_PROPERTY(int charge READ getCharge NOTIFY chargeChanged)
Q_PROPERTY(bool chargerConnected READ getChargerConnected NOTIFY chargerConnectedChanged)
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled WRITE setChargingEnabled NOTIFY chargingEnabledChanged)
2019-01-05 18:14:00 +03:00
public:
Battery(QObject* parent = nullptr);
~Battery();
int getCharge();
bool getCharging();
bool getChargerConnected();
QString getState();
2019-01-05 18:14:00 +03:00
bool getChargingEnabled();
void setChargingEnabled(bool);
2019-01-05 22:57:35 +03:00
public slots:
2019-01-05 18:14:00 +03:00
void updateData();
2019-01-05 22:57:35 +03:00
private:
2019-01-05 18:14:00 +03:00
QFile* chargeFile;
QFile* chargerConnectedFile;
QFile* stateFile;
QFile* chargingEnabledFile;
2019-01-05 18:14:00 +03:00
// Default values:
int charge = 100; // 100% full
bool chargerConnected = false; // Charger plugged in
QString state = "idle"; // dis/charging, idle, unknown
bool chargingEnabled = true; // Only ever disabled manually
int enableChargingValue = 1;
int disableChargingValue = 0;
2019-01-05 18:14:00 +03:00
int nextCharge = charge;
bool nextChargerConnected = chargerConnected;
QString nextState = state;
bool nextChargingEnabled = chargingEnabled;
2019-01-05 18:14:00 +03:00
signals:
int chargeChanged();
QString stateChanged();
bool chargingEnabledChanged();
bool chargerConnectedChanged();
2019-01-05 18:14:00 +03:00
};
#endif // BATTERY_H