blob: 642ec2444421404a278d8aa915894ab2280adcf8 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
2/*
3 * Copyright (C) 2020 by Savoir-faire Linux
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import net.jami.Models 1.0
22
23import "../../commoncomponents"
24
25import "../js/videodevicecontextmenuitemcreation.js" as VideoDeviceContextMenuItemCreation
26import "../js/selectscreenwindowcreation.js" as SelectScreenWindowCreation
27import "../js/screenrubberbandcreation.js" as ScreenRubberBandCreation
28
29Menu {
30 id: contextMenu
31
32 property string responsibleAccountId: ""
33 property string responsibleConvUid: ""
34
35 property int generalMenuSeparatorCount: 0
36 property int commonBorderWidth: 2
37
38 signal fullScreenNeeded
39
40 function activate() {
41 var deviceContextMenuInfoMap = AvAdapter.populateVideoDeviceContextMenuItem()
42
43
44 /*
45 * Somehow, the map size is undefined, so use this instead.
46 */
47 var mapSize = deviceContextMenuInfoMap["size"]
48
49 var count = 1
50 for (var deviceName in deviceContextMenuInfoMap) {
51 if (deviceName === "size")
52 continue
53 if (videoDeviceItem.itemName === "No video device") {
54 videoDeviceItem.checkable = true
55 videoDeviceItem.itemName = deviceName
56 videoDeviceItem.checked = deviceContextMenuInfoMap[deviceName]
57 if (count === mapSize)
58 contextMenu.open()
59 } else {
60 VideoDeviceContextMenuItemCreation.createVideoDeviceContextMenuItemObjects(
61 deviceName, deviceContextMenuInfoMap[deviceName],
62 count === mapSize)
63 }
64 count++
65 }
66 }
67
68 function closePotentialWindows() {
69 SelectScreenWindowCreation.destorySelectScreenWindow()
70 ScreenRubberBandCreation.destoryScreenRubberBandWindow()
71 }
72
73 implicitWidth: 200
74
75 JamiFileDialog {
76 id: jamiFileDialog
77
78 mode: JamiFileDialog.Mode.OpenFile
79
80 onAccepted: {
81 var filePath = jamiFileDialog.file
82
83
84 /*
85 * No need to trim file:///.
86 */
87 AvAdapter.shareFile(filePath)
88 }
89 }
90
91
92 /*
93 * All GeneralMenuItems should remain the same width / height.
94 * The first videoDeviceItem is to make sure the border is correct.
95 */
96 VideoCallPageContextMenuDeviceItem {
97 id: videoDeviceItem
98
99 topBorderWidth: commonBorderWidth
100 contextMenuPreferredWidth: contextMenu.implicitWidth
101 }
102
103 GeneralMenuSeparator {
104 preferredWidth: videoDeviceItem.preferredWidth
105 preferredHeight: commonBorderWidth
106
107 Component.onCompleted: {
108 generalMenuSeparatorCount++
109 }
110 }
111
112 GeneralMenuItem {
113 id: shareEntireScreenItem
114
115 itemName: qsTr("Share entire screen")
116 leftBorderWidth: commonBorderWidth
117 rightBorderWidth: commonBorderWidth
118
119 onClicked: {
120 contextMenu.close()
121 if (Qt.application.screens.length === 1) {
122 AvAdapter.shareEntireScreen(0)
123 } else {
124 SelectScreenWindowCreation.createSelectScreenWindowObject()
125 SelectScreenWindowCreation.showSelectScreenWindow()
126 }
127 }
128 }
129
130 GeneralMenuItem {
131 id: shareScreenAreaItem
132
133 itemName: qsTr("Share screen area")
134 leftBorderWidth: commonBorderWidth
135 rightBorderWidth: commonBorderWidth
136
137 onClicked: {
138 contextMenu.close()
139 if (Qt.application.screens.length === 1) {
140 ScreenRubberBandCreation.createScreenRubberBandWindowObject(
141 null, 0)
142 ScreenRubberBandCreation.showScreenRubberBandWindow()
143 } else {
144 SelectScreenWindowCreation.createSelectScreenWindowObject(true)
145 SelectScreenWindowCreation.showSelectScreenWindow()
146 }
147 }
148 }
149
150 GeneralMenuItem {
151 id: shareFileItem
152
153 itemName: qsTr("Share file")
154 leftBorderWidth: commonBorderWidth
155 rightBorderWidth: commonBorderWidth
156
157 onClicked: {
158 contextMenu.close()
159 jamiFileDialog.open()
160 }
161 }
162
163 GeneralMenuSeparator {
164 preferredWidth: videoDeviceItem.preferredWidth
165 preferredHeight: commonBorderWidth
166
167 Component.onCompleted: {
168 generalMenuSeparatorCount++
169 }
170 }
171
172 GeneralMenuItem {
173 id: fullScreenItem
174
175 property bool isFullScreen: false
176
177 itemName: isFullScreen ? qsTr("Exit full screen") : qsTr(
178 "Full screen mode")
179 iconSource: isFullScreen ? "qrc:/images/icons/ic_exit_full_screen_black.png" : "qrc:/images/icons/ic_full_screen_black.png"
180 leftBorderWidth: commonBorderWidth
181 rightBorderWidth: commonBorderWidth
182 bottomBorderWidth: commonBorderWidth
183
184 onClicked: {
185 contextMenu.close()
186 contextMenu.fullScreenNeeded()
187 isFullScreen = !isFullScreen
188 }
189 }
190
191 onClosed: {
192 videoDeviceItem.itemName = "No video device"
193 VideoDeviceContextMenuItemCreation.removeCreatedItems()
194 }
195
196 Component.onCompleted: {
197 VideoDeviceContextMenuItemCreation.setVideoContextMenuObject(
198 contextMenu)
199 }
200
201 background: Rectangle {
202 implicitWidth: contextMenu.implicitWidth
203 implicitHeight: videoDeviceItem.preferredHeight
204 * (contextMenu.count - generalMenuSeparatorCount)
205
206 border.width: commonBorderWidth
207 border.color: JamiTheme.tabbarBorderColor
208 }
209}