Debian Codegraph @

src/imports/Settings/MyselfPhoneNumbersModel.qml

raw
1 /*
2 * Copyright (C) 2015 Canonical, Ltd.
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 QOfono 0.2
19 import Lomiri.Telephony.PhoneNumber 0.1
20
21
22 ListModel {
23 id: root
24
25 function reloadNumbers()
26 {
27 root.clear()
28
29 for (var i = 0; i < simManagerList.count; i++) {
30 var item = simManagerList.itemAt(i)
31 if (item) {
32 var numbers = item.subscriberNumbers
33 if (!numbers || numbers.length === 0 ) {
34 root.append({'phoneNumber': '',
35 'network': item.networkName})
36 } else {
37 for (var n in numbers) {
38 root.append({'phoneNumber': PhoneUtils.format(numbers[n]),
39 'network': item.networkName })
40 }
41 }
42
43 }
44 }
45 }
46
47 property var priv: Item {
48 OfonoManager {
49 id: ofonoManager
50 }
51
52 Repeater {
53 id: simManagerList
54
55 model: ofonoManager.modems
56 delegate: Item {
57 property alias subscriberNumbers: simManager.subscriberNumbers
58 property alias networkName: networkRegistration.name
59
60 OfonoSimManager {
61 id: simManager
62 modemPath: modelData
63
64 onSubscriberNumbersChanged: {
65 dirtyModel.restart()
66 }
67 }
68
69 OfonoNetworkRegistration {
70 id: networkRegistration
71 modemPath: modelData
72 onNameChanged: {
73 dirtyModel.restart()
74 }
75 }
76 }
77 onCountChanged: dirtyModel.restart()
78 }
79
80 Timer {
81 id: dirtyModel
82
83 interval: 1000
84 repeat: false
85 onTriggered: root.reloadNumbers()
86 }
87 }
88 }