From ca39ce301496bcb6a210425caf1ba8d629f4630d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Sat, 15 Dec 2018 21:20:24 -0500
Subject: [PATCH] avmodel: link to deviceEvent signal

Detects when a new device is plugged or unplugged

Change-Id: Ifc9eeefad45f3916bdb26b816995028fda8a08b7
---
 src/api/avmodel.h        |  4 ++++
 src/avmodel.cpp          | 12 ++++++++++++
 src/callbackshandler.cpp | 12 ++++++++++++
 src/callbackshandler.h   | 10 ++++++++++
 4 files changed, 38 insertions(+)

diff --git a/src/api/avmodel.h b/src/api/avmodel.h
index 5e328714..2391e5fe 100644
--- a/src/api/avmodel.h
+++ b/src/api/avmodel.h
@@ -219,6 +219,10 @@ Q_SIGNALS:
      * @param id
      */
     void frameUpdated(const std::string& id);
+    /**
+     * Emitted when a device is plugged or unplugged
+     */
+    void deviceEvent();
 
 private:
     std::unique_ptr<AVModelPimpl> pimpl_;
diff --git a/src/avmodel.cpp b/src/avmodel.cpp
index 417bdfb4..094d79cb 100644
--- a/src/avmodel.cpp
+++ b/src/avmodel.cpp
@@ -110,6 +110,10 @@ public Q_SLOTS:
      * @param id
      */
     void slotFrameUpdated(const std::string& id);
+    /**
+     * Detect when a device is plugged or unplugged
+     */
+    void slotDeviceEvent();
 
 };
 
@@ -481,6 +485,8 @@ AVModelPimpl::init()
 #ifndef ENABLE_LIBWRAP
     SIZE_RENDERER = renderers_.size();
 #endif
+    connect(&callbacksHandler, &CallbacksHandler::deviceEvent,
+            this, &AVModelPimpl::slotDeviceEvent);
     connect(&callbacksHandler, &CallbacksHandler::startedDecoding,
             this, &AVModelPimpl::startedDecoding);
     connect(&callbacksHandler, &CallbacksHandler::stoppedDecoding,
@@ -684,6 +690,12 @@ AVModelPimpl::slotFrameUpdated(const std::string& id)
     emit linked_.frameUpdated(id);
 }
 
+void
+AVModelPimpl::slotDeviceEvent()
+{
+    emit linked_.deviceEvent();
+}
+
 } // namespace lrc
 
 #include "api/moc_avmodel.cpp"
diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp
index f94c98b2..6779d3f5 100644
--- a/src/callbackshandler.cpp
+++ b/src/callbackshandler.cpp
@@ -200,6 +200,12 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
             this,
             &CallbacksHandler::slotStoppedDecoding,
             Qt::QueuedConnection);
+
+    connect(&VideoManager::instance(),
+            &VideoManagerInterface::deviceEvent,
+            this,
+            &CallbacksHandler::slotDeviceEvent,
+            Qt::QueuedConnection);
 }
 
 CallbacksHandler::~CallbacksHandler()
@@ -481,5 +487,11 @@ CallbacksHandler::slotStoppedDecoding(const QString& id, const QString& shmPath)
     emit stoppedDecoding(id.toStdString(), shmPath.toStdString());
 }
 
+void
+CallbacksHandler::slotDeviceEvent()
+{
+    emit deviceEvent();
+}
+
 
 } // namespace lrc
diff --git a/src/callbackshandler.h b/src/callbackshandler.h
index d070a42c..78b9e59a 100644
--- a/src/callbackshandler.h
+++ b/src/callbackshandler.h
@@ -248,6 +248,11 @@ Q_SIGNALS:
      */
     void stoppedDecoding(const std::string& id, const std::string& shmPath);
 
+    /**
+     * Emitted when a device is plugged or unplugged
+     */
+    void deviceEvent();
+
 private Q_SLOTS:
     /**
      * Emit newAccountMessage
@@ -446,6 +451,11 @@ private Q_SLOTS:
      */
     void slotStoppedDecoding(const QString& id, const QString& shmPath);
 
+    /**
+     * Detect when a device is plugged or unplugged
+     */
+    void slotDeviceEvent();
+
 
 private:
     const api::Lrc& parent;
-- 
GitLab