From d0e28b473605e15467c6ecd1a2a355ebe03faa81 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Michal=20Mal=C3=BD?= <madcatxster@devoid-pointer.net>
Date: Thu, 30 Jul 2015 00:59:14 +0200
Subject: [PATCH] Don't empty effect slots combobox when the already selected
 interface is selected again

---
 deviceprober.h      |  2 +-
 linuxdeviceprober.h |  2 +-
 mainwindow.cpp      | 13 ++++++++-----
 mainwindow.h        |  2 +-
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/deviceprober.h b/deviceprober.h
index 4d5c30d..69519b7 100644
--- a/deviceprober.h
+++ b/deviceprober.h
@@ -28,7 +28,7 @@ public:
   const DeviceInterfaces type;
 
 protected:
-  explicit DeviceProber() : type(DeviceInterfaces::NONE) {}
+  explicit DeviceProber(DeviceInterfaces _type) : type(_type) {}
 };
 
 
diff --git a/linuxdeviceprober.h b/linuxdeviceprober.h
index 79ab94a..52bb35e 100644
--- a/linuxdeviceprober.h
+++ b/linuxdeviceprober.h
@@ -7,7 +7,7 @@
 class LinuxDeviceProber : public DeviceProber
 {
 public:
-  explicit LinuxDeviceProber() {}
+  explicit LinuxDeviceProber() : DeviceProber(DeviceProber::DeviceInterfaces::LINUX) {}
   void closeAllDevices();
   DeviceList listDevices();
   std::shared_ptr<FFBDevice> openDevice(const QString& id);
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 130d20e..17041ae 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -53,13 +53,13 @@ MainWindow::MainWindow(const QString& title, QWidget* parent) :
   connect(ui->qpb_upload, SIGNAL(clicked()), this, SLOT(onUploadEffectClicked()));
 }
 
-void MainWindow::createDeviceProber(const DeviceProber::DeviceInterfaces iface)
+bool MainWindow::createDeviceProber(const DeviceProber::DeviceInterfaces iface)
 {
   std::shared_ptr<DeviceProber> prober;
 
   if (m_prober != nullptr) {
     if (m_prober->type == iface)
-      return;
+      return false;
 
     m_prober->closeAllDevices();
   }
@@ -74,6 +74,7 @@ void MainWindow::createDeviceProber(const DeviceProber::DeviceInterfaces iface)
   }
 
   m_prober = prober;
+  return true;
 }
 
 EffectSettings* MainWindow::effectSettingsByType(FFBEffectTypes type)
@@ -227,16 +228,18 @@ void MainWindow::onInterfaceSelected(const int cboxIdx)
     return;
   }
 
-  ui->cbox_effectSlots->clear();
 
   iface = static_cast<DeviceProber::DeviceInterfaces>(rawIface);
-  createDeviceProber(iface);
+  if (!createDeviceProber(iface))
+    return;
+
+  ui->cbox_effectSlots->clear();
   fillDeviceList();
 }
 
 void MainWindow::onRefreshDevicesClicked()
 {
-  //fillDeviceList();
+  fillDeviceList();
 }
 
 void MainWindow::onRemoveEffectClicked()
diff --git a/mainwindow.h b/mainwindow.h
index 417d4b3..6770fa0 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -35,7 +35,7 @@ private:
     CANT_UPLOAD_EFFECT
   };
 
-  void createDeviceProber(const DeviceProber::DeviceInterfaces iface);
+  bool createDeviceProber(const DeviceProber::DeviceInterfaces iface);
   EffectSettings* effectSettingsByType(FFBEffectTypes type);
   QString effectTypeToEffectName(const FFBEffectTypes type) const;
   void fillDeviceList();
-- 
2.43.5