Update VehicleSignals usage
[apps/homescreen.git] / homescreen / src / mastervolume.cpp
index 8d7ecb4..d173ef2 100644 (file)
@@ -27,45 +27,49 @@ MasterVolume::MasterVolume(QObject* parent) :
 
        if (m_vs) {
                QObject::connect(m_vs, &VehicleSignals::connected, this, &MasterVolume::onConnected);
-               QObject::connect(m_vs, &VehicleSignals::authorized, this, &MasterVolume::onAuthorized);
-               QObject::connect(m_vs, &VehicleSignals::disconnected, this, &MasterVolume::onDisconnected);
 
                m_vs->connect();
        }
 }
 
+MasterVolume::~MasterVolume()
+{
+       delete m_vs;
+}
+
 qint32 MasterVolume::getVolume() const
 {
        return m_volume;
 }
 
-void MasterVolume::setVolume(qint32 volume)
+void MasterVolume::setVolume(quint32 volume)
 {
        if (m_volume == volume)
                return;
 
        m_volume = volume;
 
-       if (!(m_vs && m_connected))
-               return;
-
-       m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume));
+       if (m_vs)
+               m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", volume, true);
 }
 
-void MasterVolume::onConnected()
+void MasterVolume::updateVolume(QString value)
 {
-       if (!m_vs)
-               return;
-
-       m_vs->authorize();
+       bool ok;
+       quint32 volume = value.toUInt(&ok);
+       if (ok) {
+               volume = qBound(0U, volume, 100U);
+               if (m_volume != volume) {
+                       m_volume = volume;
+                       emit VolumeChanged();
+               }
+       }
 }
 
-void MasterVolume::onAuthorized()
+void MasterVolume::onConnected()
 {
-       if (!m_vs)
-               return;
-
-       m_connected = true;
+       if (!m_vs)
+               return;
 
        QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse);
        QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
@@ -74,27 +78,6 @@ void MasterVolume::onAuthorized()
        m_vs->get("Vehicle.Cabin.Infotainment.Media.Volume");
 }
 
-void MasterVolume::onDisconnected()
-{
-       QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onGetSuccessResponse);
-       QObject::disconnect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
-
-       m_connected = false;
-}
-
-void MasterVolume::updateVolume(QString value)
-{
-       bool ok;
-       qint32 volume = value.toInt(&ok);
-       if (ok) {
-               volume = qBound(0, volume, 100);
-               if (m_volume != volume) {
-                       m_volume = volume;
-                       emit VolumeChanged();
-               }
-       }
-}
-
 void MasterVolume::onGetSuccessResponse(QString path, QString value, QString timestamp)
 {
        if (path == "Vehicle.Cabin.Infotainment.Media.Volume") {