瀏覽代碼

PlayerComponent: avoid blank entry in settings if audio device missing

If an audio device was removed (due to hot plug, e.g. HDMI cable
disconnected), don't show a blank entry. Instead, show a dummy entry
that informs the user that the device is disconnected. It's also
possible to select another device and reselect the dummy one, as long as
the audio device list isn't updated by another hotplug event.

This should be much nicer to users than the weird blank entry.
Vincent Lang 8 年之前
父節點
當前提交
381939cb90
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      src/player/PlayerComponent.cpp

+ 15 - 0
src/player/PlayerComponent.cpp

@@ -860,6 +860,9 @@ void PlayerComponent::checkCurrentAudioDevice(const QSet<QString>& old_devs, con
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 void PlayerComponent::updateAudioDeviceList()
 {
+  QString userDevice = SettingsComponent::Get().value(SETTINGS_SECTION_AUDIO, "device").toString();
+  bool userDeviceFound = false;
+
   QVariantList settingList;
   QVariant list = getAudioDeviceList();
   QSet<QString> devices;
@@ -875,6 +878,18 @@ void PlayerComponent::updateAudioDeviceList()
     entry["title"] = dmap["description"];
 
     settingList << entry;
+
+    if (userDevice == dmap["name"])
+      userDeviceFound = true;
+  }
+
+  if (!userDeviceFound)
+  {
+    QVariantMap entry;
+    entry["value"] = userDevice;
+    entry["title"] = "[Disconnected device: " + userDevice + "]";
+
+    settingList << entry;
   }
 
   SettingsComponent::Get().updatePossibleValues(SETTINGS_SECTION_AUDIO, "device", settingList);