Use current ringtone volume. Fixes issue #9

This commit is contained in:
Matti Viljanen 2020-12-29 22:59:15 +02:00
parent 6b3085857c
commit 7b490275ba
5 changed files with 54 additions and 1 deletions

View file

@ -2,7 +2,7 @@ TARGET = harbour-batterybuddy-daemon
CONFIG = sailfishapp qt console c++11 sailfish_build CONFIG = sailfishapp qt console c++11 sailfish_build
QT = core network dbus multimedia QT = core network dbus multimedia dbus
PKGCONFIG += nemonotifications-qt5 PKGCONFIG += nemonotifications-qt5
@ -17,11 +17,13 @@ DEFINES += APP_NAME=\"\\\"$$TARGET\\\"\"
HEADERS += \ HEADERS += \
src/battery.h \ src/battery.h \
src/mynotification.h \ src/mynotification.h \
src/profile.h \
src/settings.h src/settings.h
SOURCES += \ SOURCES += \
src/battery.cpp \ src/battery.cpp \
src/mynotification.cpp \ src/mynotification.cpp \
src/profile.cpp \
src/settings.cpp \ src/settings.cpp \
src/harbour-batterybuddy-daemon.cpp src/harbour-batterybuddy-daemon.cpp

View file

@ -37,6 +37,9 @@ void MyNotification::send(QString title, QString body, QString soundFile)
title = title.replace("\"", "\\\""); title = title.replace("\"", "\\\"");
body = body.replace("\"", "\\\""); body = body.replace("\"", "\\\"");
int vol = profile.getRingtoneVolume();
sound.setVolume(vol);
playSound = true; playSound = true;
if(sound.media() != QUrl::fromLocalFile(soundFile)) { if(sound.media() != QUrl::fromLocalFile(soundFile)) {
// Signalled to play() // Signalled to play()

View file

@ -22,6 +22,7 @@
#include <QTimer> #include <QTimer>
#include <QMediaPlayer> #include <QMediaPlayer>
#include <nemonotifications-qt5/notification.h> #include <nemonotifications-qt5/notification.h>
#include "profile.h"
#include <QDebug> #include <QDebug>
class MyNotification : public QObject class MyNotification : public QObject
@ -41,6 +42,7 @@ private:
Notification notification; Notification notification;
QMediaPlayer sound; QMediaPlayer sound;
bool playSound; bool playSound;
Profile profile;
private slots: private slots:
void soundLoadedChanged(QMediaPlayer::MediaStatus newStatus); void soundLoadedChanged(QMediaPlayer::MediaStatus newStatus);

28
service/src/profile.cpp Normal file
View file

@ -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);
}

18
service/src/profile.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef PROFILE_H
#define PROFILE_H
#include <QObject>
#include <QtDBus/QtDBus>
class Profile : public QObject
{
Q_OBJECT
public:
explicit Profile(QObject *parent = nullptr);
uint getRingtoneVolume();
private:
QDBusConnection connection = QDBusConnection::sessionBus();
};
#endif // PROFILE_H