Drop compatibility for SFOS versions 4.2 and older
This commit is contained in:
parent
96366d7931
commit
10095a41e9
9 changed files with 7 additions and 279 deletions
|
@ -1,38 +0,0 @@
|
|||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
// Source: http://www.xargs.com/qml/process.html
|
||||
// Copyright © 2015 John Temples
|
||||
|
||||
#include <QProcess>
|
||||
#include <QVariant>
|
||||
|
||||
class Process : public QProcess {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Process(QObject *parent = nullptr) : QProcess(parent) { }
|
||||
|
||||
Q_INVOKABLE void start(const QString &program, const QVariantList &arguments) {
|
||||
QStringList args;
|
||||
|
||||
// convert QVariantList from QML to QStringList for QProcess
|
||||
|
||||
for (int i = 0; i < arguments.length(); i++)
|
||||
args << arguments[i].toString();
|
||||
|
||||
QProcess::start(program, args);
|
||||
QProcess::waitForStarted(1000);
|
||||
QProcess::waitForFinished(1000);
|
||||
}
|
||||
|
||||
Q_INVOKABLE QByteArray readAll() {
|
||||
return QProcess::readAll();
|
||||
}
|
||||
|
||||
Q_INVOKABLE int errorCode() {
|
||||
return QProcess::exitCode();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PROCESS_H
|
|
@ -21,6 +21,7 @@ Requires: sailfishsilica-qt5 >= 0.10.9
|
|||
Requires: nemo-qml-plugin-configuration-qt5
|
||||
Requires: nemo-qml-plugin-notifications-qt5
|
||||
Requires: libkeepalive
|
||||
Requires: sailfish-version >= 4.3
|
||||
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
||||
BuildRequires: pkgconfig(nemonotifications-qt5)
|
||||
BuildRequires: pkgconfig(Qt5Core)
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
# 0 = Compatible with SFOS 4.0+
|
||||
# 1 = Compatible SFOS 2.2+
|
||||
LEGACY_BUILD = 0
|
||||
|
||||
TARGET = harbour-batterybuddy-daemon
|
||||
|
||||
CONFIG += console
|
||||
|
||||
contains(LEGACY_BUILD, 0) { QT = core dbus }
|
||||
contains(LEGACY_BUILD, 1) { QT = core dbus multimedia }
|
||||
QT = core dbus
|
||||
|
||||
PKGCONFIG += nemonotifications-qt5
|
||||
|
||||
|
@ -16,7 +9,6 @@ VERSION = 3.16.2-1
|
|||
|
||||
DEFINES += APP_VERSION=\"\\\"$$VERSION\\\"\"
|
||||
DEFINES += APP_NAME=\"\\\"$$TARGET\\\"\"
|
||||
DEFINES += LEGACY_BUILD=$${LEGACY_BUILD}
|
||||
|
||||
# Use "--verbose" and "--debug" at runtime.
|
||||
# See main() and logger.h for details.
|
||||
|
@ -27,25 +19,15 @@ LIBS += -lkeepalive -lnemonotifications-qt5
|
|||
HEADERS += \
|
||||
src/battery.h \
|
||||
src/logger.h \
|
||||
src/settings.h
|
||||
src/settings.h \
|
||||
src/mynotification.h
|
||||
|
||||
SOURCES += \
|
||||
src/battery.cpp \
|
||||
src/logger.cpp \
|
||||
src/settings.cpp \
|
||||
src/harbour-batterybuddy-daemon.cpp
|
||||
|
||||
contains(LEGACY_BUILD, 1) {
|
||||
HEADERS += src/profile.h \
|
||||
src/mynotification_sfos2.h
|
||||
SOURCES += src/profile.cpp \
|
||||
src/mynotification_sfos2.cpp
|
||||
}
|
||||
|
||||
contains(LEGACY_BUILD, 0) {
|
||||
HEADERS += src/mynotification.h
|
||||
SOURCES += src/mynotification.cpp
|
||||
}
|
||||
src/harbour-batterybuddy-daemon.cpp \
|
||||
src/mynotification.cpp
|
||||
|
||||
OTHER_FILES += harbour-batterybuddy-daemon.service
|
||||
|
||||
|
|
|
@ -30,13 +30,9 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb
|
|||
logE(QString("Log level set to %1").arg((logLevel == 0 ? "low" : (logLevel == 1 ? "medium" : "high"))));
|
||||
}
|
||||
|
||||
#if LEGACY_BUILD == 1
|
||||
chargeNotification = new MyNotification(logger, this);
|
||||
healthNotification = new MyNotification(logger, this);
|
||||
#else
|
||||
chargeNotification = new MyNotification(this);
|
||||
healthNotification = new MyNotification(this);
|
||||
#endif
|
||||
|
||||
// Number: charge percentage, e.g. 42
|
||||
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
|
||||
logE("Capacity file: " + chargeFile->fileName() + (chargeFile->exists() ? " OK" : " doesn't exist"));
|
||||
|
|
|
@ -28,11 +28,7 @@
|
|||
#include <QCoreApplication>
|
||||
#include <keepalive/backgroundactivity.h>
|
||||
#include "settings.h"
|
||||
#if LEGACY_BUILD == 1
|
||||
#include "mynotification_sfos2.h"
|
||||
#else
|
||||
#include "mynotification.h"
|
||||
#endif
|
||||
#include "logger.h"
|
||||
|
||||
class Battery : public QObject
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
||||
*
|
||||
* 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
|
||||
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Matti Viljanen
|
||||
*/
|
||||
#include "mynotification_sfos2.h"
|
||||
|
||||
MyNotification::MyNotification(Logger *newLogger, QObject* parent) : QObject(parent)
|
||||
{
|
||||
notification.setAppName("Battery Buddy");
|
||||
// Set this manually, so that the correct icon is used.
|
||||
notification.setAppIcon("harbour-batterybuddy");
|
||||
|
||||
logger = newLogger;
|
||||
profile = new Profile(logger, this);
|
||||
|
||||
playSound = false;
|
||||
sound.setAudioRole(QAudio::NotificationRole);
|
||||
connect(&sound, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
|
||||
this, SLOT(soundLoadedChanged(QMediaPlayer::MediaStatus)));
|
||||
}
|
||||
|
||||
MyNotification::~MyNotification() { }
|
||||
|
||||
void MyNotification::send(QString title, QString body, QString soundFile)
|
||||
{
|
||||
title = title.replace("\"", "\\\"");
|
||||
body = body.replace("\"", "\\\"");
|
||||
|
||||
int vol = profile->getRingtoneVolume();
|
||||
sound.setVolume(vol);
|
||||
|
||||
playSound = true;
|
||||
if(sound.media() != QUrl::fromLocalFile(soundFile)) {
|
||||
// Signalled to play()
|
||||
sound.setMedia(QUrl::fromLocalFile(soundFile));
|
||||
}
|
||||
else if (playSound){
|
||||
// Must manually trigger play()
|
||||
sound.play();
|
||||
playSound = false;
|
||||
}
|
||||
|
||||
notification.setSummary(title);
|
||||
notification.setBody(body);
|
||||
notification.setPreviewSummary(title);
|
||||
notification.setPreviewBody(body);
|
||||
notification.setUrgency(Notification::Normal);
|
||||
notification.publish();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void MyNotification::close()
|
||||
{
|
||||
notification.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void MyNotification::soundLoadedChanged(const QMediaPlayer::MediaStatus newStatus) {
|
||||
if(playSound && newStatus == QMediaPlayer::LoadedMedia) {
|
||||
sound.play();
|
||||
playSound = false;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
||||
*
|
||||
* 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
|
||||
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Matti Viljanen
|
||||
*/
|
||||
#ifndef MYNOTIFICATION_H
|
||||
#define MYNOTIFICATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMediaPlayer>
|
||||
#include <nemonotifications-qt5/notification.h>
|
||||
#include "profile.h"
|
||||
#include "logger.h"
|
||||
|
||||
class MyNotification : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MyNotification(Logger* newLogger, QObject* parent = nullptr);
|
||||
~MyNotification();
|
||||
|
||||
public slots:
|
||||
void send(QString title, QString body, QString soundFile);
|
||||
void close();
|
||||
|
||||
private:
|
||||
Notification notification;
|
||||
Logger* logger;
|
||||
QString noteID = "1";
|
||||
QMediaPlayer sound;
|
||||
bool playSound;
|
||||
Profile* profile;
|
||||
|
||||
private slots:
|
||||
void soundLoadedChanged(const QMediaPlayer::MediaStatus newStatus);
|
||||
};
|
||||
|
||||
#endif // MYNOTIFICATION_H
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
||||
*
|
||||
* 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
|
||||
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Matti Viljanen
|
||||
*/
|
||||
#include "profile.h"
|
||||
|
||||
Profile::Profile(Logger* newLogger, QObject *parent) : QObject(parent)
|
||||
{
|
||||
logger = newLogger;
|
||||
}
|
||||
|
||||
int Profile::getRingtoneVolume() {
|
||||
const QString dots = "com.nokia.profiled";
|
||||
const QString slashes = "/com/nokia/profiled";
|
||||
QDBusInterface interface(dots, slashes, dots, connection);
|
||||
|
||||
QDBusMessage message = interface.call("get_profile");
|
||||
QString profile = message.arguments().at(0).toString();
|
||||
logD("Active profile:" + profile);
|
||||
|
||||
if(profile == "silent") {
|
||||
logD("Returning volume: 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
message = interface.call("get_value", "profile", "ringing.alert.volume");
|
||||
int volume = message.arguments().at(0).toInt();
|
||||
logD(QString("Ringtone volume: %1").arg(volume));
|
||||
|
||||
return (volume >= 0 && volume <= 100 ? volume : 0);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
||||
*
|
||||
* 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
|
||||
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Matti Viljanen
|
||||
*/
|
||||
#ifndef PROFILE_H
|
||||
#define PROFILE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
#include "logger.h"
|
||||
|
||||
class Profile : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
int getRingtoneVolume();
|
||||
explicit Profile(Logger* newLogger, QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
Logger* logger;
|
||||
QDBusConnection connection = QDBusConnection::sessionBus();
|
||||
};
|
||||
|
||||
#endif // PROFILE_H
|
Loading…
Reference in a new issue