Split project into GUI application and CLI service

This commit is contained in:
Matti Viljanen 2020-04-24 11:18:26 +03:00
parent b067580d92
commit cbf7e7cdbc
No known key found for this signature in database
GPG key ID: CF32A1495158F888
43 changed files with 236 additions and 81 deletions

View file

@ -0,0 +1,83 @@
# NOTICE:
#
# Application name defined in TARGET has a corresponding QML filename.
# If name defined in TARGET is changed, the following needs to be done
# to match new name:
# - corresponding QML filename must be changed
# - desktop icon filename must be changed
# - desktop filename must be changed
# - icon definition filename in desktop file must be changed
# - translation filenames have to be changed
# The name of your application
TARGET = harbour-batterybuddy
CONFIG += console sailfishapp sailfishapp_i18n
VER = 2.2
REL = 2
VERSION = $${VER}-$${REL}
$$system(bash update-spec-version.sh $$TARGET $$VER $$REL)
DEFINES += APP_VERSION=\"\\\"$$VERSION\\\"\"
DEFINES += APP_NAME=\"\\\"$$TARGET\\\"\"
# Do not define QT_NO_DEBUG_OUTPUT!
# Use "--verbose" and "--debug" at runtime instead.
# See main() for details.
#DEFINES += QT_NO_DEBUG_OUTPUT
HEADERS += \
src/battery.h \
src/settings.h
SOURCES += src/harbour-batterybuddy.cpp \
src/battery.cpp \
src/settings.cpp
DISTFILES += qml/harbour-batterybuddy.qml \
qml/components/AboutLabel.qml \
qml/components/MyLabel.qml \
qml/components/MySlider.qml \
qml/pages\LicensePage.qml \
qml/cover/CoverPage.qml \
../rpm/harbour-batterybuddy.spec \
service/clear-write-permissions.sh \
service/harbour-batterybuddy.service \
service/set-write-permissions.sh \
translations/*.ts \
harbour-batterybuddy.desktop \
qml/pages/MainPage.qml \
qml/pages/AboutPage.qml \
qml/pages/InfoPage.qml \
../rpm/harbour-batterybuddy.changes \
qml/components/BatteryGraph.qml \
qml/pages/SettingsPage.qml \
qml/components/MyDetailItem.qml
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
TRANSLATIONS += translations/*.ts
OTHER_FILES += service/clear-write-permissions.sh \
service/harbour-batterybuddy.service \
service/set-write-permissions.sh
service.files = service
service.path = /usr/share/$${TARGET}
INSTALLS += service
SUBDIRS += service
# Begin: include sound files
#OTHER_FILES += sounds/upperLimit.ogg \
# sounds/lowerLimit.ogg \
#sounds.files = sounds
#sounds.path = /usr/share/$${TARGET}
#INSTALLS += sounds
# End: include sound files

View file

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View file

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

View file

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

View file

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View file

@ -1,81 +1,3 @@
# NOTICE:
#
# Application name defined in TARGET has a corresponding QML filename.
# If name defined in TARGET is changed, the following needs to be done
# to match new name:
# - corresponding QML filename must be changed
# - desktop icon filename must be changed
# - desktop filename must be changed
# - icon definition filename in desktop file must be changed
# - translation filenames have to be changed
# The name of your application
TARGET = harbour-batterybuddy
CONFIG += console sailfishapp sailfishapp_i18n
VER = 2.2
REL = 2
VERSION = $${VER}-$${REL}
$$system(bash update-spec-version.sh $$TARGET $$VER $$REL)
DEFINES += APP_VERSION=\"\\\"$$VERSION\\\"\"
DEFINES += APP_NAME=\"\\\"$$TARGET\\\"\"
# Do not define QT_NO_DEBUG_OUTPUT!
# Use "--verbose" and "--debug" at runtime instead.
# See main() for details.
#DEFINES += QT_NO_DEBUG_OUTPUT
HEADERS += \
src/battery.h \
src/settings.h
SOURCES += src/harbour-batterybuddy.cpp \
src/battery.cpp \
src/settings.cpp
DISTFILES += qml/harbour-batterybuddy.qml \
qml/components/AboutLabel.qml \
qml/components/MyLabel.qml \
qml/components/MySlider.qml \
qml/pages\LicensePage.qml \
qml/cover/CoverPage.qml \
rpm/harbour-batterybuddy.spec \
service/clear-write-permissions.sh \
service/harbour-batterybuddy.service \
service/set-write-permissions.sh \
translations/*.ts \
harbour-batterybuddy.desktop \
qml/pages/MainPage.qml \
qml/pages/AboutPage.qml \
qml/pages/InfoPage.qml \
rpm/harbour-batterybuddy.changes \
qml/components/BatteryGraph.qml \
qml/pages/SettingsPage.qml \
qml/components/MyDetailItem.qml
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
TRANSLATIONS += translations/*.ts
OTHER_FILES += service/clear-write-permissions.sh \
service/harbour-batterybuddy.service \
service/set-write-permissions.sh
service.files = service
service.path = /usr/share/$${TARGET}
INSTALLS += service
# Begin: include sound files
#OTHER_FILES += sounds/upperLimit.ogg \
# sounds/lowerLimit.ogg \
#sounds.files = sounds
#sounds.path = /usr/share/$${TARGET}
#INSTALLS += sounds
# End: include sound files
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = application service

22
service/service.pro Normal file
View file

@ -0,0 +1,22 @@
TARGET = harbour-batterybuddy-daemon
CONFIG = qt c++11 sailfish_build
QT = dbus network xml
HEADERS += \
src/filewatcher.h
SOURCES += \
src/filewatcher.cpp \
src/harbour-batterybuddy-daemon.cpp
OTHER_FILES += harbour-batterybuddy-daemon.service
#include($$PWD/../common/common.pri)
service.path = /usr/lib/systemd/user/
service.files += harbour-batterybuddy-daemon.service
target.path = /usr/bin/
INSTALLS += target service

View file

@ -0,0 +1,94 @@
#include "filewatcher.h"
FileWatcher::FileWatcher(QObject *parent) : QObject(parent)
{
QString filename;
// Number: charge percentage, e.g. 42
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
qInfo() << "Reading capacity from" << chargeFile->fileName();
// String: charging, discharging, full, empty, unknown (others?)
stateFile = new QFile("/sys/class/power_supply/battery/status", this);
qInfo() << "Reading charge state from" << stateFile->fileName();
// Number: 0 or 1
chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this);
qInfo() << "Reading charger status from" << chargerConnectedFile->fileName();
// Find and use the file to control the charger
// e.g. for Sony Xperia XA2
filename = "/sys/class/power_supply/battery/input_suspend";
if(!chargerControlFile && QFile::exists(filename)) {
chargerControlFile = new QFile(filename, this);
enableChargingValue = 0;
disableChargingValue = 1;
}
// e.g. for Sony Xperia Z3 Compact Tablet
filename = "/sys/class/power_supply/battery/charging_enabled";
if(!chargerControlFile && QFile::exists(filename)) {
chargerControlFile = new QFile(filename, this);
enableChargingValue = 1;
disableChargingValue = 0;
}
// e.g. for Jolla Phone
filename = "/sys/class/power_supply/usb/charger_disable";
if(!chargerControlFile && QFile::exists(filename)) {
chargerControlFile = new QFile(filename, this);
enableChargingValue = 0;
disableChargingValue = 1;
}
if(!chargerControlFile) {
qWarning() << "Charger control file not found!";
qWarning() << "Please contact the developer with your device model!";
}
// If we found a usable file, check that it is writable
if(chargerControlFile) {
if(chargerControlFile->open(QIODevice::WriteOnly)) {
qInfo() << "Controlling charging via" << chargerControlFile->fileName();
chargerControlFile->close();
}
else {
delete chargerControlFile;
chargerControlFile = Q_NULLPTR;
qWarning() << "Charger control file" << chargerControlFile->fileName() << "is not writable";
qWarning() << "Charger control feature disabled";
}
}
chargeWatcher = new QFileSystemWatcher(QStringList(chargeFile->fileName()), this);
stateWatcher = new QFileSystemWatcher(QStringList(stateFile->fileName()), this);
chargerConnectedWatcher = new QFileSystemWatcher(QStringList(chargerConnectedFile->fileName()), this);
connect(chargeWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateCharge()));
connect(stateWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateState()));
connect(chargerConnectedWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateChargerConnected()));
return;
}
FileWatcher::~FileWatcher()
{
}
void FileWatcher::updateCharge()
{
}
void FileWatcher::updateState()
{
}
void FileWatcher::updateChargerConnected()
{
}

28
service/src/filewatcher.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef FILEWATCHER_H
#define FILEWATCHER_H
#include <QObject>
#include <QFileSystemWatcher>
#include <QFile>
#include <QDebug>
class FileWatcher : public QObject
{
Q_OBJECT
public:
FileWatcher(QObject* parent = nullptr);
~FileWatcher();
private:
QFileSystemWatcher *chargeWatcher, *stateWatcher, *chargerConnectedWatcher;
QFile *chargeFile, *stateFile, *chargerConnectedFile, *chargerControlFile;
int enableChargingValue = 1, disableChargingValue = 0;
private slots:
void updateCharge();
void updateState();
void updateChargerConnected();
};
#endif // FILEWATCHER_H

View file

@ -0,0 +1,6 @@
#include "filewatcher.h"
int main()
{
return 0;
}