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
|
import GSettings 1.0
import QtQuick 2.4
import QtMultimedia 5.6
import SystemSettings 1.0
import Ubuntu.Content 1.3
import Ubuntu.Components 1.3
import Ubuntu.Components.ListItems 1.3 as ListItem
import Ubuntu.SystemSettings.Sound 1.0
import QMenuModel 0.1
import "utilities.js" as Utilities
ItemPage {
property variant soundDisplayNames:
Utilities.buildSoundValues(soundFileNames)
property variant soundFileNames: refreshSoundFileNames()
property bool showStopButton: false
property int soundType // 0: ringtone, 1: message
property string soundsDir
property var activeTransfer
onSoundFileNamesChanged: {
soundDisplayNames = Utilities.buildSoundValues(soundFileNames)
updateSelectedIndex()
}
id: soundsPage
flickable: scrollWidget
function refreshSoundFileNames() {
var customDir = mountPoint + "/custom/usr/share/" + soundsDir;
if (soundType === 0)
return backendInfo.listSounds([soundsDir, customDir, backendInfo.customRingtonePath])
return backendInfo.listSounds([soundsDir, customDir])
}
UbuntuSoundPanel {
id: backendInfo
onIncomingCallSoundChanged: {
if (soundType == 0)
soundSelector.selectedIndex =
Utilities.indexSelectedFile(soundFileNames,
incomingCallSound)
}
onIncomingMessageSoundChanged: {
if (soundType == 1)
soundSelector.selectedIndex =
Utilities.indexSelectedFile(soundFileNames,
incomingMessageSound)
}
}
GSettings {
id: soundSettings
schema.id: "com.ubuntu.touch.sound"
}
QDBusActionGroup {
id: soundActionGroup
busType: DBus.SessionBus
busName: "com.canonical.indicator.sound"
objectPath: "/com/canonical/indicator/sound"
Component.onCompleted: start()
}
Audio {
id: soundEffect
audioRole: MediaPlayer.alert
}
function setRingtone(path) {
if (soundType == 0) {
soundSettings.incomingCallSound = path
backendInfo.incomingCallSound = path
} else if (soundType == 1) {
soundSettings.incomingMessageSound = path
backendInfo.incomingMessageSound = path
}
soundFileNames = refreshSoundFileNames()
previewTimer.start()
soundEffect.source = path
soundEffect.play()
}
function updateSelectedIndex() {
if (soundType == 0)
soundSelector.selectedIndex =
Utilities.indexSelectedFile(soundFileNames,
backendInfo.incomingCallSound)
else if (soundType == 1)
soundSelector.selectedIndex =
Utilities.indexSelectedFile(soundFileNames,
backendInfo.incomingMessageSound)
}
Flickable {
id: scrollWidget
anchors.fill: parent
contentWidth: parent.width
contentHeight: selectorColumn.height + stopItem.height
boundsBehavior: (contentHeight > height) ?
Flickable.DragAndOvershootBounds :
Flickable.StopAtBounds
/* Set the direction to workaround https://bugreports.qt-project.org/browse/QTBUG-31905
otherwise the UI might end up in a situation where scrolling doesn't work */
flickableDirection: Flickable.VerticalFlick
Column {
id: selectorColumn
anchors.left: parent.left
anchors.right: parent.right
ListItem.ItemSelector {
id: soundSelector
expanded: true
model: soundDisplayNames
selectedIndex: {
updateSelectedIndex()
}
onDelegateClicked: {
setRingtone(soundFileNames[index])
}
}
ListItem.Standard {
id: customRingtone
text: i18n.tr("Custom Ringtone")
visible: soundType === 0
progression: true
onClicked: pageStack.addPageToNextColumn(soundsPage, picker)
}
}
}
ListItem.SingleControl {
id: stopItem
anchors.bottom: parent.bottom
control: AbstractButton {
id: stopButton
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
focus: false
width: height
height: units.gu(4)
enabled: soundEffect.playbackState == Audio.PlayingState
visible: enabled
onClicked: soundEffect.stop()
Rectangle {
anchors.fill: parent
radius: width * 0.5
border.color: UbuntuColors.warmGrey
border.width: 1
}
Rectangle {
width: parent.height * 0.4
height: width
smooth: true
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}
color: UbuntuColors.warmGrey
}
}
Rectangle {
anchors.fill: parent
z: parent.z - 1
visible: stopButton.visible
color: Theme.palette.normal.background
}
}
Timer {
id: previewTimer
onTriggered: soundEffect.stop()
interval: 30000
}
Connections {
id: contentHubConnection
property var ringtoneCallback
target: activeTransfer ? activeTransfer : null
onStateChanged: {
if (activeTransfer.state === ContentTransfer.Charged) {
if (activeTransfer.items.length > 0) {
var item = activeTransfer.items[0];
var toneUri;
if (item.move(backendInfo.customRingtonePath)) {
toneUri = item.url;
} else {
toneUri = backendInfo.customRingtonePath + "/" + item.url.toString().split("/").splice(-1,1);
}
ringtoneCallback(toneUri);
}
}
}
}
Page {
id: picker
visible: false
title: i18n.tr("Choose from")
ContentPeerPicker {
id: peerPicker
visible: parent.visible
handler: ContentHandler.Source
contentType: ContentType.Music
showTitle: false
onPeerSelected: {
pageStack.removePages(soundsPage);
// requests an active transfer from peer
function startContentTransfer(callback) {
if (callback)
contentHubConnection.ringtoneCallback = callback
var transfer = peer.request();
if (transfer !== null) {
soundsPage.activeTransfer = transfer;
}
}
peer.selectionType = ContentTransfer.Single;
startContentTransfer(function(uri) {
setRingtone(uri.toString().replace("file:///", "/"));
});
}
onCancelPressed: pageStack.removePages(soundsPage);
}
}
ContentTransferHint {
anchors.fill: parent
activeTransfer: soundsPage.activeTransfer
}
}
|