forked from dawndiy/recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
285 lines (245 loc) · 9.19 KB
/
Main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
* Copyright (C) 2016 DawnDIY <[email protected]>
*
* This file is part of Recorder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import QtSystemInfo 5.0
import QtMultimedia 5.5
import QtGraphicalEffects 1.0
import Qt.labs.settings 1.0
import Ubuntu.Components 1.3
import Ubuntu.Content 1.3
// import Ubuntu.PerformanceMetrics 1.0
import AudioRecorder 1.0
import "ui"
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
id: root
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "audio-recorder.ubuntu-dawndiy"
property string appVersion: "1.0.3"
width: units.gu(50)
height: units.gu(75)
function notification(text, duration) {
var noti = Qt.createComponent(Qt.resolvedUrl("component/SnackBar.qml"))
noti.createObject(root, {text: text, duration: duration})
}
function showIntro() {
// debug
// settings.version = ""
if (settings.version != root.appVersion) {
pageLayout.forceSinglePage = true
pageLayout.addPageToCurrentColumn(homePage, introPage)
}
}
Component.onCompleted: {
showIntro()
}
Settings {
id: settings
property string version: ""
property string audioCodec: "default"
property string fileContainer: "default"
property int channels: 1
property int encodingMode: -1
property int encodingQuality: -1
property int bitrate: -1
property int recordsSorting: 0
property bool disableScreenSaver: true
property bool showSoundWave: true
property int microphoneVolume: 90
}
ScreenSaver {
id: screenSaver
screenSaverEnabled: !settings.disableScreenSaver || !Qt.application.active
}
Recorder {
id: recorder
readonly property var channelData: {
'default_index': 0,
'list': [ { name: '1', value: 1 }, { name: '2', value: 2 } ]
}
readonly property var qualityData: {
'default_index': 2,
'list': [
// TRANSLATORS: This is a quality option in Record Quality.
{ name: i18n.tr("Very Low Quality"), value: 0},
// TRANSLATORS: This is a quality option in Record Quality.
{ name: i18n.tr("Low Quality"), value: 1},
// TRANSLATORS: This is a quality option in Record Quality.
{ name: i18n.tr("%1 (default)").arg(i18n.tr("Normal Quality")), value: 2},
// TRANSLATORS: This is a quality option in Record Quality.
{ name: i18n.tr("High Quality"), value: 3},
// TRANSLATORS: This is a quality option in Record Quality.
{ name: i18n.tr("Very High Quality"), value: 4}
]
}
readonly property var encodingModeData: {
'default_index': 0,
'list': [
// TRANSLATORS: This is an option in Encoding Mode. It means set audio quality using defaults options.
{ name: i18n.tr("%1 (default)").arg(i18n.tr("Constant Quality")), value: 0},
// TRANSLATORS: This is an option in Encoding Mode. It means set audio quality using bitrate.
{ name: i18n.tr("Constant Bitrate"), value: 1}
]
}
readonly property var bitrateData: {
'default_index': 0,
'list': [
{ name: i18n.tr("%1 (default)").arg('32000'), value: 32000 },
{ name: '64000', value: 64000 },
{ name: '128000', value: 128000 },
{ name: '192000', value: 192000 },
{ name: '256000', value: 256000 }
]
}
property var codecData: ({})
property var containerData: ({})
function getDataName(data, value) {
var name = ''
if (!data.list) {
return name
}
if (value === -1 || value === "default") {
return data.list[data.default_index].name
}
for (var i = 0; i < data.list.length; i++) {
var item = data.list[i]
if (item.value == value) {
name = item.name
break
}
}
return name
}
audioCodec: settings.audioCodec
fileContainer: settings.fileContainer
channels: settings.channels
encodingMode: settings.encodingMode == -1 ?
Recorder.QualityMode : settings.encodingMode == 0 ?
Recorder.QualityMode : Recorder.BitrateMode
encodingQuality: settings.encodingQuality == -1 ?
Recorder.NormalQuality : settings.encodingQuality
bitrate: settings.bitrate == -1 ?
32000 : bitrateList[settings.bitrate]
microphoneVolume: settings.microphoneVolume
onError: {
console.log(errorMessage)
// TRANSLATORS: This a reminder when some thing error.
var tip = i18n.tr(" (Reset your settings will fix this.)")
notification(errorMessage + tip, 5)
}
Component.onCompleted: {
// detect audio codec
var codec_list = recorder.supportedAudioCodecs()
if (codec_list.length > 0) {
recorder.codecData.list = []
}
for (var i = 0; i < codec_list.length; i++) {
var codec = codec_list[i]
var codec_item = { name: codec, value: codec}
if (codec === "audio/vorbis") {
codec_item.name = i18n.tr("%1 (default)").arg(codec_item.name)
recorder.codecData.default_index = i
}
recorder.codecData.list.push(codec_item)
}
// detect file container
var container_list = recorder.supportedContainers()
if (container_list.length > 0) {
recorder.containerData.list = []
}
for (var i = 0; i < container_list.length; i++) {
var container = container_list[i]
var container_item = { name: container, value: container }
if (container === "ogg") {
container_item.name = i18n.tr("%1 (default)").arg(container_item.name)
recorder.containerData.default_index = i
}
recorder.containerData.list.push(container_item)
}
// console.log("---", JSON.stringify(recorder.codecData))
// console.log("---", JSON.stringify(recorder.containerData))
}
}
MediaPlayer {
id: player
}
// Venice Blue
LinearGradient {
opacity: 1
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(parent.width, parent.height)
gradient: Gradient {
GradientStop { position: 0.0; color: "#85D8CE" }
GradientStop { position: 1.0; color: "#085078" }
}
}
AdaptivePageLayout {
id: pageLayout
property bool forceSinglePage: true
function addPageToNext(sourcePage, page, properties) {
pageLayout.addPageToNextColumn(sourcePage, page, properties)
forceSinglePage = false
}
function removePage(page) {
pageLayout.removePages(page)
forceSinglePage = true
}
anchors.fill: parent
primaryPage: homePage
layouts: PageColumnsLayout {
when: width > units.gu(80) && !pageLayout.forceSinglePage
PageColumn {
minimumWidth: units.gu(50)
maximumWidth: units.gu(80)
preferredWidth: units.gu(50)
}
PageColumn {
fillWidth: true
}
}
HomePage {
id: homePage
}
IntroPage {
id: introPage
onStartApp: {
pageLayout.forceSinglePage = false
pageLayout.removePages(introPage)
settings.version = root.appVersion
}
}
}
// PerformanceOverlay {
// active: true
// }
Connections {
target: ContentHub
onExportRequested: {
console.debug("Export Requested")
pageLayout.addPageToCurrentColumn(
homePage, Qt.resolvedUrl("ui/RecordsPage.qml"),
{ state: "exporter", transfer: transfer })
}
}
}