diff --git a/service/service.pro b/service/service.pro
index 2c42ad8..768f517 100644
--- a/service/service.pro
+++ b/service/service.pro
@@ -1,18 +1,24 @@
+# 0 = Build for SFOS 3.4+ (use the latest Sailfish Application SDK)
+# 1 = Build for SFOS 2.2+ (use Sailfish Application SDK 1807)
+LEGACY_BUILD = 0
+
TARGET = harbour-batterybuddy-daemon
CONFIG += sailfishapp console
-QT = core dbus
+contains(LEGACY_BUILD, 0) { QT = core dbus }
+contains(LEGACY_BUILD, 1) { QT = core dbus multimedia }
PKGCONFIG += nemonotifications-qt5
# Keep this in sync with "application.pro"
-VER = 3.12
-REL = 3
+VER = 3.13
+REL = 1
VERSION = $${VER}-$${REL}
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.
@@ -20,17 +26,27 @@ DEFINES += QT_NO_DEBUG_OUTPUT
HEADERS += \
src/battery.h \
- src/mynotification.h \
src/logger.h \
src/settings.h
SOURCES += \
src/battery.cpp \
- src/mynotification.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
+}
+
OTHER_FILES += harbour-batterybuddy-daemon.service
service.path = /usr/lib/systemd/user/
diff --git a/service/src/battery.cpp b/service/src/battery.cpp
index 88799f6..08866d9 100644
--- a/service/src/battery.cpp
+++ b/service/src/battery.cpp
@@ -34,9 +34,13 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
highNotifyTimer = new QTimer(this);
lowNotifyTimer = new QTimer(this);
healthNotifyTimer = new QTimer(this);
+#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/mynotification_sfos2.cpp b/service/src/mynotification_sfos2.cpp
new file mode 100644
index 0000000..f31b14f
--- /dev/null
+++ b/service/src/mynotification_sfos2.cpp
@@ -0,0 +1,78 @@
+/**
+ * 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.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.setSound(soundFile);
+ 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
new file mode 100644
index 0000000..a66ee48
--- /dev/null
+++ b/service/src/mynotification_sfos2.h
@@ -0,0 +1,52 @@
+/**
+ * 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
+#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
new file mode 100644
index 0000000..61ac8e7
--- /dev/null
+++ b/service/src/profile.cpp
@@ -0,0 +1,44 @@
+/**
+ * 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
new file mode 100644
index 0000000..e0da0dc
--- /dev/null
+++ b/service/src/profile.h
@@ -0,0 +1,37 @@
+/**
+ * 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