From 10095a41e919a825ecd032bce8b97f703bc43322 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 20 Mar 2022 19:37:47 +0200 Subject: [PATCH] Drop compatibility for SFOS versions 4.2 and older --- application/src/process.h | 38 -------------- rpm/harbour-batterybuddy.spec | 1 + service/service.pro | 28 ++-------- service/src/battery.cpp | 6 +-- service/src/battery.h | 4 -- service/src/mynotification_sfos2.cpp | 77 ---------------------------- service/src/mynotification_sfos2.h | 51 ------------------ service/src/profile.cpp | 44 ---------------- service/src/profile.h | 37 ------------- 9 files changed, 7 insertions(+), 279 deletions(-) delete mode 100644 application/src/process.h delete mode 100644 service/src/mynotification_sfos2.cpp delete mode 100644 service/src/mynotification_sfos2.h delete mode 100644 service/src/profile.cpp delete mode 100644 service/src/profile.h diff --git a/application/src/process.h b/application/src/process.h deleted file mode 100644 index bc0a06d..0000000 --- a/application/src/process.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef PROCESS_H -#define PROCESS_H - -// Source: http://www.xargs.com/qml/process.html -// Copyright © 2015 John Temples - -#include -#include - -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 diff --git a/rpm/harbour-batterybuddy.spec b/rpm/harbour-batterybuddy.spec index eceb43b..c19a1d5 100644 --- a/rpm/harbour-batterybuddy.spec +++ b/rpm/harbour-batterybuddy.spec @@ -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) diff --git a/service/service.pro b/service/service.pro index 1ebc25a..3d96213 100644 --- a/service/service.pro +++ b/service/service.pro @@ -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 diff --git a/service/src/battery.cpp b/service/src/battery.cpp index ace4d3d..3f08f0e 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -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")); diff --git a/service/src/battery.h b/service/src/battery.h index 5e2a6b3..18ff6ed 100644 --- a/service/src/battery.h +++ b/service/src/battery.h @@ -28,11 +28,7 @@ #include #include #include "settings.h" -#if LEGACY_BUILD == 1 -#include "mynotification_sfos2.h" -#else #include "mynotification.h" -#endif #include "logger.h" class Battery : public QObject diff --git a/service/src/mynotification_sfos2.cpp b/service/src/mynotification_sfos2.cpp deleted file mode 100644 index 3f882cb..0000000 --- a/service/src/mynotification_sfos2.cpp +++ /dev/null @@ -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 . - * - * 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; - } -} diff --git a/service/src/mynotification_sfos2.h b/service/src/mynotification_sfos2.h deleted file mode 100644 index 166c063..0000000 --- a/service/src/mynotification_sfos2.h +++ /dev/null @@ -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 . - * - * Author: Matti Viljanen - */ -#ifndef MYNOTIFICATION_H -#define MYNOTIFICATION_H - -#include -#include -#include -#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 diff --git a/service/src/profile.cpp b/service/src/profile.cpp deleted file mode 100644 index 61ac8e7..0000000 --- a/service/src/profile.cpp +++ /dev/null @@ -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 . - * - * 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); -} diff --git a/service/src/profile.h b/service/src/profile.h deleted file mode 100644 index e0da0dc..0000000 --- a/service/src/profile.h +++ /dev/null @@ -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 . - * - * Author: Matti Viljanen - */ -#ifndef PROFILE_H -#define PROFILE_H - -#include -#include -#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