diff --git a/service/service.pro b/service/service.pro index bc71ece..e051142 100644 --- a/service/service.pro +++ b/service/service.pro @@ -2,7 +2,7 @@ TARGET = harbour-batterybuddy-daemon CONFIG = sailfishapp qt console c++11 sailfish_build -QT = core network dbus multimedia +QT = core network dbus multimedia dbus PKGCONFIG += nemonotifications-qt5 @@ -17,11 +17,13 @@ DEFINES += APP_NAME=\"\\\"$$TARGET\\\"\" HEADERS += \ src/battery.h \ src/mynotification.h \ + src/profile.h \ src/settings.h SOURCES += \ src/battery.cpp \ src/mynotification.cpp \ + src/profile.cpp \ src/settings.cpp \ src/harbour-batterybuddy-daemon.cpp diff --git a/service/src/mynotification.cpp b/service/src/mynotification.cpp index 3033c43..2dfef2f 100644 --- a/service/src/mynotification.cpp +++ b/service/src/mynotification.cpp @@ -37,6 +37,9 @@ 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() diff --git a/service/src/mynotification.h b/service/src/mynotification.h index 5032b4b..517ad15 100644 --- a/service/src/mynotification.h +++ b/service/src/mynotification.h @@ -22,6 +22,7 @@ #include #include #include +#include "profile.h" #include class MyNotification : public QObject @@ -41,6 +42,7 @@ private: Notification notification; QMediaPlayer sound; bool playSound; + Profile profile; private slots: void soundLoadedChanged(QMediaPlayer::MediaStatus newStatus); diff --git a/service/src/profile.cpp b/service/src/profile.cpp new file mode 100644 index 0000000..5c6f8af --- /dev/null +++ b/service/src/profile.cpp @@ -0,0 +1,28 @@ +#include "profile.h" + +Profile::Profile(QObject *parent) : QObject(parent) +{ + +} + +uint Profile::getRingtoneVolume() { + QDBusInterface interface("com.nokia.profiled", + "/com/nokia/profiled", + "com.nokia.profiled", + connection); + + QDBusMessage message = interface.call("get_profile"); + QString profile = message.arguments().at(0).toString(); + qDebug() << "Active profile:" << profile; + + if(profile == "silent") { + qDebug() << "Returning volume: 0"; + return 0; + } + + message = interface.call("get_value", "profile", "ringing.alert.volume"); + int volume = message.arguments().at(0).toInt(); + qDebug() << "Ringtone volume:" << 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..cc605e8 --- /dev/null +++ b/service/src/profile.h @@ -0,0 +1,18 @@ +#ifndef PROFILE_H +#define PROFILE_H + +#include +#include + +class Profile : public QObject +{ + Q_OBJECT +public: + explicit Profile(QObject *parent = nullptr); + uint getRingtoneVolume(); + +private: + QDBusConnection connection = QDBusConnection::sessionBus(); +}; + +#endif // PROFILE_H