Debian Codegraph @

src/imports/Lomiri/AddressBook/ContactView/ContactDetailRingtoneView.qml

raw
1 /*
2 * Copyright (C) 2023 Ubports Foundation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19 import Lomiri.Components.ListItems 1.3
20 import QtContacts 5.0
21
22 import Lomiri.AddressBook.Base 0.1
23
24 import Lomiri.Components.Themes.Ambiance 0.1
25
26 ContactDetailBase {
27 id: root
28
29 detailType: ContactDetail.Ringtone
30
31 activeFocusOnTab: false
32 implicitHeight: empty ? 0 : contents.implicitHeight
33 visible: implicitHeight > 0
34
35 property bool empty: true
36
37 onDetailChanged: {
38 if (detail) {
39 populateValues(detail)
40 }
41 }
42
43 function populateValues(detail) {
44 ringTones.clear()
45
46 if (detail) {
47 const audioUrl = detail.value(Ringtone.AudioRingtoneUrl)
48 const videoUrl = detail.value(Ringtone.VideoRingtoneUrl)
49 const messageUrl = detail.value(Ringtone.VibrationRingtoneUrl)
50
51 root.empty = !audioUrl //&& !videoUrl && !messageUrl
52 if (audioUrl) {
53 ringTones.append({"type": Ringtone.AudioRingtoneUrl, "label": i18n.dtr("lomiri-addressbook-app", "Incoming call"), "value": audioUrl ? audioUrl.toString() : ""})
54 }
55 /*
56 if (videoUrl) {
57 ringTones.append({"type": Ringtone.VideoRingtoneUrl, "label": i18n.dtr("lomiri-addressbook-app", "Incoming video"), "value": audioUrl ? videoUrl.toString() : ""})
58 }
59 if (messageUrl) {
60 ringTones.append({"type": Ringtone.VibrationRingtoneUrl, "label": i18n.dtr("lomiri-addressbook-app", "Incoming message"), "value": messageUrl ? messageUrl.toString() : ""})
61 }
62 */
63 }
64 }
65
66 function soundName(soundPath) {
67
68 if (soundPath.length > 0) {
69 /* The display name starts with an uppercase char, and replace special chars with spaces */
70 var title = soundPath.split('/').pop().split('.').slice(0,-1).join(" ").replace(/[._-]/g, " ")
71 if (title.length > 0) {
72 return title[0].toUpperCase() + title.slice(1)
73 }
74 }
75
76 return i18n.tr("Default sound")
77 }
78
79 ListModel {
80 id: ringTones
81 }
82
83 Column {
84 id: contents
85 spacing: units.gu(1)
86 width: parent.width
87
88 ContactDetailTitle {
89 id: header
90 title: i18n.dtr("lomiri-addressbook-app", "Custom ringtones")
91 }
92
93 Repeater {
94 model: ringTones
95
96 Column {
97
98 anchors {
99 margins: units.gu(2)
100 left: parent.left
101 right: parent.right
102 }
103
104 Label {
105 id: input
106 text: soundName(value)
107 }
108
109 Label {
110 id: typeLabel
111
112 verticalAlignment: Text.AlignVCenter
113 elide: Text.ElideRight
114 text: label
115 // style
116 fontSize: "small"
117 opacity: 0.8
118 }
119 }
120 }
121 }
122
123 Connections {
124 target: contact
125 function onContactChanged() {
126 if (contact) {
127 populateValues(contact.detail(root.detailType))
128 }
129 }
130 }
131 }