+
+ if (!(m_vs && m_connected))
+ return;
+
+ m_vs->set("Vehicle.Cabin.Infotainment.Media.Volume", QString::number(volume));
+}
+
+void MasterVolume::onConnected()
+{
+ if (!m_vs)
+ return;
+
+ m_vs->authorize();
+}
+
+void MasterVolume::onAuthorized()
+{
+ if (!m_vs)
+ return;
+
+ m_connected = true;
+
+ QObject::connect(m_vs, &VehicleSignals::getSuccessResponse, this, &MasterVolume::onGetSuccessResponse);
+ QObject::connect(m_vs, &VehicleSignals::signalNotification, this, &MasterVolume::onSignalNotification);
+
+ m_vs->subscribe("Vehicle.Cabin.Infotainment.Media.Volume");
+ 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") {
+ updateVolume(value);
+ emit VolumeChanged();
+ }
+}
+
+void MasterVolume::onSignalNotification(QString path, QString value, QString timestamp)
+{
+ if (path == "Vehicle.Cabin.Infotainment.Media.Volume")
+ updateVolume(value);