From 010930febe2c28374c65e25c3147f08bdc2efecc Mon Sep 17 00:00:00 2001
From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Date: Tue, 7 Feb 2023 14:21:35 -0300
Subject: [PATCH] misc: fix close file sharing

Change-Id: I9450db0658741059620c052e8ddf602976fc2983
GitLab: #968
---
 src/app/avadapter.cpp                         | 21 +++++++++++++------
 src/app/avadapter.h                           |  2 +-
 src/app/currentcall.cpp                       |  3 +++
 src/app/currentcall.h                         |  1 +
 src/app/mainview/components/CallOverlay.qml   |  2 +-
 .../components/CallViewContextMenu.qml        |  2 +-
 6 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/app/avadapter.cpp b/src/app/avadapter.cpp
index 6689e96da..412ab61f2 100644
--- a/src/app/avadapter.cpp
+++ b/src/app/avadapter.cpp
@@ -290,14 +290,23 @@ AvAdapter::getListWindows()
 }
 
 void
-AvAdapter::stopSharing()
+AvAdapter::stopSharing(const QString& source)
 {
     auto callId = lrcInstance_->getCurrentCallId();
-    if (!callId.isEmpty()) {
-        lrcInstance_->getCurrentCallModel()->removeMedia(callId,
-                                                         libjami::Media::Details::MEDIA_TYPE_VIDEO,
-                                                         libjami::Media::VideoProtocolPrefix::DISPLAY,
-                                                         muteCamera_);
+    if (!source.isEmpty() && !callId.isEmpty()) {
+        if (source.startsWith(libjami::Media::VideoProtocolPrefix::DISPLAY)) {
+            qDebug() << "Stopping display: " << source;
+            lrcInstance_->getCurrentCallModel()->removeMedia(callId,
+                                                            libjami::Media::Details::MEDIA_TYPE_VIDEO,
+                                                            libjami::Media::VideoProtocolPrefix::DISPLAY,
+                                                            muteCamera_);
+        } else {
+            qDebug() << "Stopping file: " << source;
+            lrcInstance_->getCurrentCallModel()->removeMedia(callId,
+                                                            libjami::Media::Details::MEDIA_TYPE_VIDEO,
+                                                            libjami::Media::VideoProtocolPrefix::FILE,
+                                                            muteCamera_);
+        }
     }
 }
 
diff --git a/src/app/avadapter.h b/src/app/avadapter.h
index 0ce2ee22b..23fdd18a5 100644
--- a/src/app/avadapter.h
+++ b/src/app/avadapter.h
@@ -94,7 +94,7 @@ protected:
     Q_INVOKABLE void getListWindows();
 
     // Stop sharing the screen or file
-    Q_INVOKABLE void stopSharing();
+    Q_INVOKABLE void stopSharing(const QString& source = {});
 
     Q_INVOKABLE void startAudioMeter();
     Q_INVOKABLE void stopAudioMeter();
diff --git a/src/app/currentcall.cpp b/src/app/currentcall.cpp
index 3dcd17663..6eb4fbd50 100644
--- a/src/app/currentcall.cpp
+++ b/src/app/currentcall.cpp
@@ -108,6 +108,7 @@ CurrentCall::updateCallInfo()
     bool isAudioMuted {};
     bool isVideoMuted {};
     bool isSharing {};
+    QString sharingSource {};
     bool isCapturing {};
     QString previewId {};
     using namespace libjami::Media;
@@ -117,6 +118,7 @@ CurrentCall::updateCallInfo()
                 if (media[MediaAttributeKey::SOURCE].startsWith(VideoProtocolPrefix::DISPLAY)
                     || media[MediaAttributeKey::SOURCE].startsWith(VideoProtocolPrefix::FILE)) {
                     isSharing = true;
+                    sharingSource = media[MediaAttributeKey::SOURCE];
                 }
                 if (media[MediaAttributeKey::ENABLED] == TRUE_STR
                     && media[MediaAttributeKey::MUTED] == FALSE_STR && previewId.isEmpty()) {
@@ -138,6 +140,7 @@ CurrentCall::updateCallInfo()
     set_isAudioMuted(isAudioMuted);
     set_isVideoMuted(isVideoMuted);
     set_isSharing(isSharing);
+    set_sharingSource(sharingSource);
     set_isCapturing(isCapturing);
     set_isHandRaised(callModel->isHandRaised(id_));
     set_isModerator(callModel->isModerator(id_));
diff --git a/src/app/currentcall.h b/src/app/currentcall.h
index 5ad19071f..4b128b9b1 100644
--- a/src/app/currentcall.h
+++ b/src/app/currentcall.h
@@ -43,6 +43,7 @@ class CurrentCall final : public QObject
     QML_RO_PROPERTY(bool, isRecordingRemotely)
     QML_RO_PROPERTY(QStringList, remoteRecorderNameList)
     QML_RO_PROPERTY(bool, isSharing)
+    QML_RO_PROPERTY(QString, sharingSource)
     QML_RO_PROPERTY(bool, isHandRaised)
     QML_RO_PROPERTY(bool, isConference)
     QML_RO_PROPERTY(bool, isModerator)
diff --git a/src/app/mainview/components/CallOverlay.qml b/src/app/mainview/components/CallOverlay.qml
index 66e5822ec..3e51c48cf 100644
--- a/src/app/mainview/components/CallOverlay.qml
+++ b/src/app/mainview/components/CallOverlay.qml
@@ -165,7 +165,7 @@ Item {
             function onShowInputPanelClicked() { sipInputPanel.open() }
             function onShareScreenClicked() { openShareScreen() }
             function onShareWindowClicked() { openShareWindow() }
-            function onStopSharingClicked() { AvAdapter.stopSharing() }
+            function onStopSharingClicked() { AvAdapter.stopSharing(CurrentCall.sharingSource) }
             function onShareScreenAreaClicked() { openShareScreenArea() }
             function onRecordCallClicked() { CallAdapter.recordThisCallToggle() }
             function onShareFileClicked() { jamiFileDialog.open() }
diff --git a/src/app/mainview/components/CallViewContextMenu.qml b/src/app/mainview/components/CallViewContextMenu.qml
index ca5d50977..4a7aa35d3 100644
--- a/src/app/mainview/components/CallViewContextMenu.qml
+++ b/src/app/mainview/components/CallViewContextMenu.qml
@@ -114,7 +114,7 @@ ContextMenuAutoLoader {
             itemName: JamiStrings.stopSharing
             iconSource: JamiResources.share_stop_black_24dp_svg
             iconColor: JamiTheme.redColor
-            onClicked: AvAdapter.stopSharing()
+            onClicked: AvAdapter.stopSharing(CurrentCall.sharingSource)
         },
         GeneralMenuItem {
             id: shareScreen
-- 
GitLab