harbour-batterybuddy/application/src/battery.h

83 lines
2.5 KiB
C
Raw Normal View History

/**
* Battery Buddy, a Sailfish application to prolong battery lifetime
*
2020-04-26 19:01:20 +03:00
* Copyright (C) 2019-2020 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
2020-03-24 11:02:30 +03:00
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Matti Viljanen
*/
2020-03-21 04:27:09 +03:00
#ifndef BATTERY_H
#define BATTERY_H
#include <QObject>
2019-01-05 18:14:00 +03:00
#include <QString>
#include <QFile>
2020-03-21 13:32:50 +03:00
#include <QStandardPaths>
#include <QHostInfo>
#include <QDebug>
2020-03-20 21:58:01 +03:00
#include "settings.h"
2020-06-12 01:04:11 +03:00
#include "process.h"
2019-01-05 18:14:00 +03:00
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:
2020-03-20 21:58:01 +03:00
Battery(Settings* newSettings, QObject* parent = nullptr);
2019-01-05 18:14:00 +03:00
~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:
2020-04-26 18:20:54 +03:00
QFile* chargeFile = nullptr;
QFile* chargerConnectedFile = nullptr;
QFile* stateFile = nullptr;
QFile* chargingEnabledFile = nullptr;
Settings* settings = nullptr;
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;
2020-03-20 21:58:01 +03:00
bool chargerIsEnabled = true;
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:
2020-03-28 11:11:23 +03:00
void chargeChanged(int);
void stateChanged(QString);
void chargingEnabledChanged(bool);
void chargerConnectedChanged(bool);
2019-01-05 18:14:00 +03:00
};
#endif // BATTERY_H