Merge lp:~unity-api-team/indicator-network/mobile_data_switch into lp:indicator-network
- mobile_data_switch
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Antti Kaijanmäki |
Proposed branch: | lp:~unity-api-team/indicator-network/mobile_data_switch |
Merge into: | lp:indicator-network |
Diff against target: |
8959 lines (+7904/-17) 62 files modified
CMakeLists.txt (+2/-0) data/com.ubuntu.connectivity1.Modem.xml (+9/-0) data/com.ubuntu.connectivity1.Private.xml (+8/-0) data/com.ubuntu.connectivity1.Sim.xml (+16/-0) scripts/CMakeLists.txt (+5/-0) scripts/disable-mobile-data.sh (+8/-0) scripts/enable-mobile-data.sh (+8/-0) scripts/get-mobile-data-enabled.sh (+6/-0) scripts/get-modems.sh (+6/-0) scripts/get-sim-for-mobile-data.sh (+6/-0) scripts/get-sims.sh (+6/-0) scripts/monitor-private-properties.sh (+7/-0) scripts/set-sim-for-mobile-data.sh (+8/-0) src/connectivity-api/connectivity-qml/CMakeLists.txt (+1/-1) src/connectivity-api/connectivity-qml/plugin.cpp (+14/-1) src/connectivity-api/connectivity-qml/proxy-model.h (+80/-0) src/connectivity-api/connectivity-qt/CMakeLists.txt (+21/-2) src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp (+92/-0) src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h (+24/-0) src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp (+112/-0) src/connectivity-api/connectivity-qt/connectivityqt/modem.h (+68/-0) src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp (+172/-0) src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h (+78/-0) src/connectivity-api/connectivity-qt/connectivityqt/path.cpp (+103/-0) src/connectivity-api/connectivity-qt/connectivityqt/path.h (+59/-0) src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp (+153/-0) src/connectivity-api/connectivity-qt/connectivityqt/sim.h (+90/-0) src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp (+214/-0) src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h (+93/-0) src/indicator/CMakeLists.txt (+21/-0) src/indicator/connectivity-service/connectivity-service.cpp (+185/-0) src/indicator/connectivity-service/connectivity-service.h (+17/-0) src/indicator/connectivity-service/dbus-modem.cpp (+98/-0) src/indicator/connectivity-service/dbus-modem.h (+83/-0) src/indicator/connectivity-service/dbus-sim.cpp (+149/-0) src/indicator/connectivity-service/dbus-sim.h (+103/-0) src/indicator/factory.cpp (+12/-2) src/indicator/factory.h (+3/-1) src/indicator/menu-builder.cpp (+3/-1) src/indicator/nmofono/manager-impl.cpp (+210/-0) src/indicator/nmofono/manager-impl.h (+12/-0) src/indicator/nmofono/manager.h (+26/-0) src/indicator/nmofono/wwan/modem.cpp (+63/-2) src/indicator/nmofono/wwan/modem.h (+10/-0) src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp (+251/-0) src/indicator/nmofono/wwan/qofono-sim-wrapper.h (+77/-0) src/indicator/nmofono/wwan/sim-manager.cpp (+271/-0) src/indicator/nmofono/wwan/sim-manager.h (+56/-0) src/indicator/nmofono/wwan/sim.cpp (+582/-0) src/indicator/nmofono/wwan/sim.h (+182/-0) src/indicator/sections/wwan-section.cpp (+9/-5) src/indicator/sections/wwan-section.h (+1/-1) src/qdbus-stubs/dbus-types.h (+13/-0) tests/data/phonesim/sim_general.xml (+3677/-0) tests/integration/CMakeLists.txt (+2/-0) tests/integration/indicator-network-test-base.cpp (+8/-0) tests/integration/indicator-network-test-base.h (+1/-0) tests/integration/qml/test.qml (+119/-0) tests/integration/test-connectivity-api-modem.cpp (+53/-0) tests/integration/test-connectivity-api-sim.cpp (+68/-0) tests/integration/test-connectivity-api.cpp (+21/-0) tests/integration/test-indicator.cpp (+49/-1) |
To merge this branch: | bzr merge lp:~unity-api-team/indicator-network/mobile_data_switch |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Indicator Applet Developers | Pending | ||
Review via email: mp+289028@code.launchpad.net |
Commit message
New Connectivity Service Private API for managing mobile data and SIM cards.
Description of the change
- 576. By Antti Kaijanmäki
-
add stuff to .Private
- 577. By Antti Kaijanmäki
-
add switch to the menu
- 578. By Antti Kaijanmäki
-
.
- 579. By Antti Kaijanmäki
-
add sim and modem ADAPTORS
- 580. By Antti Kaijanmäki
-
modem and sim Interfaces.
- 581. By Antti Kaijanmäki
-
some test skeletons
- 582. By Antti Kaijanmäki
-
Sim: add Primmary phone number
- 583. By Antti Kaijanmäki
-
some more test skeletons
- 584. By Antti Kaijanmäki
-
introduce wwan::Sim
- 585. By Antti Kaijanmäki
-
factory: introduce mobileDataSwitch
- 586. By Antti Kaijanmäki
-
Augment nmofono::Manager interface.
- 587. By Antti Kaijanmäki
-
commit for a while..
- 588. By Antti Kaijanmäki
-
added scripts/
- 589. By Antti Kaijanmäki
-
Get the ConnectionManager interface for actually managing the data connection.
- 590. By Antti Kaijanmäki
-
add phonesim/
general_ sim.xml - 591. By Antti Kaijanmäki
-
QML API start
- 592. By Antti Kaijanmäki
-
merge upstream
- 593. By Antti Kaijanmäki
-
finish qml bindings.
- 594. By Antti Kaijanmäki
-
add simple qml program
- 595. By Antti Kaijanmäki
-
cleanups
Unmerged revisions
- 595. By Antti Kaijanmäki
-
cleanups
- 594. By Antti Kaijanmäki
-
add simple qml program
- 593. By Antti Kaijanmäki
-
finish qml bindings.
- 592. By Antti Kaijanmäki
-
merge upstream
- 591. By Antti Kaijanmäki
-
QML API start
- 590. By Antti Kaijanmäki
-
add phonesim/
general_ sim.xml - 589. By Antti Kaijanmäki
-
Get the ConnectionManager interface for actually managing the data connection.
- 588. By Antti Kaijanmäki
-
added scripts/
- 587. By Antti Kaijanmäki
-
commit for a while..
- 586. By Antti Kaijanmäki
-
Augment nmofono::Manager interface.
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-02-15 09:31:38 +0000 | |||
3 | +++ CMakeLists.txt 2016-04-26 11:24:03 +0000 | |||
4 | @@ -139,3 +139,5 @@ | |||
5 | 139 | ) | 139 | ) |
6 | 140 | 140 | ||
7 | 141 | endif() | 141 | endif() |
8 | 142 | |||
9 | 143 | add_subdirectory(scripts) | ||
10 | 142 | 144 | ||
11 | === added file 'data/com.ubuntu.connectivity1.Modem.xml' | |||
12 | --- data/com.ubuntu.connectivity1.Modem.xml 1970-01-01 00:00:00 +0000 | |||
13 | +++ data/com.ubuntu.connectivity1.Modem.xml 2016-04-26 11:24:03 +0000 | |||
14 | @@ -0,0 +1,9 @@ | |||
15 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
16 | 2 | |||
17 | 3 | <node> | ||
18 | 4 | <interface name="com.ubuntu.connectivity1.Modem"> | ||
19 | 5 | <property name="Index" type="i" access="read" /> | ||
20 | 6 | <property name="Serial" type="s" access="read" /> | ||
21 | 7 | <property name="Sim" type="o" access="read" /> | ||
22 | 8 | </interface> | ||
23 | 9 | </node> | ||
24 | 0 | 10 | ||
25 | === modified file 'data/com.ubuntu.connectivity1.Private.xml' | |||
26 | --- data/com.ubuntu.connectivity1.Private.xml 2015-12-04 13:18:04 +0000 | |||
27 | +++ data/com.ubuntu.connectivity1.Private.xml 2016-04-26 11:24:03 +0000 | |||
28 | @@ -52,6 +52,14 @@ | |||
29 | 52 | 52 | ||
30 | 53 | <property name="VpnConnections" type="ao" access="read"/> | 53 | <property name="VpnConnections" type="ao" access="read"/> |
31 | 54 | 54 | ||
32 | 55 | <property name="MobileDataEnabled" type="b" access="readwrite"/> | ||
33 | 56 | |||
34 | 57 | <property name="SimForMobileData" type="o" access="readwrite"/> | ||
35 | 58 | |||
36 | 59 | <property name="Modems" type="ao" access="read"/> | ||
37 | 60 | |||
38 | 61 | <property name="Sims" type="ao" access="read"/> | ||
39 | 62 | |||
40 | 55 | <signal name="ReportError"> | 63 | <signal name="ReportError"> |
41 | 56 | <arg type="i" direction="out" name="reason"/> | 64 | <arg type="i" direction="out" name="reason"/> |
42 | 57 | </signal> | 65 | </signal> |
43 | 58 | 66 | ||
44 | === added file 'data/com.ubuntu.connectivity1.Sim.xml' | |||
45 | --- data/com.ubuntu.connectivity1.Sim.xml 1970-01-01 00:00:00 +0000 | |||
46 | +++ data/com.ubuntu.connectivity1.Sim.xml 2016-04-26 11:24:03 +0000 | |||
47 | @@ -0,0 +1,16 @@ | |||
48 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
49 | 2 | |||
50 | 3 | <node> | ||
51 | 4 | <interface name="com.ubuntu.connectivity1.Sim"> | ||
52 | 5 | <property name="Imsi" type="s" access="read" /> | ||
53 | 6 | <property name="PrimaryPhoneNumber" type="s" access="read" /> | ||
54 | 7 | <property name="Locked" type="b" access="read" /> | ||
55 | 8 | <property name="Present" type="b" access="read" /> | ||
56 | 9 | <property name="Mcc" type="s" access="read" /> | ||
57 | 10 | <property name="Mnc" type="s" access="read" /> | ||
58 | 11 | <property name="PreferredLanguages" type="as" access="read" /> | ||
59 | 12 | <property name="DataRoamingEnabled" type="b" access="readwrite" /> | ||
60 | 13 | |||
61 | 14 | <method name="Unlock" /> | ||
62 | 15 | </interface> | ||
63 | 16 | </node> | ||
64 | 0 | 17 | ||
65 | === added directory 'scripts' | |||
66 | === added file 'scripts/CMakeLists.txt' | |||
67 | --- scripts/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
68 | +++ scripts/CMakeLists.txt 2016-04-26 11:24:03 +0000 | |||
69 | @@ -0,0 +1,5 @@ | |||
70 | 1 | |||
71 | 2 | file(GLOB_RECURSE SCRIPT_FILES | ||
72 | 3 | ${CMAKE_CURRENT_SOURCE_DIR}/*.sh | ||
73 | 4 | ) | ||
74 | 5 | add_custom_target(scriptfiles SOURCES ${SCRIPT_FILES}) | ||
75 | 0 | 6 | ||
76 | === added file 'scripts/disable-mobile-data.sh' | |||
77 | --- scripts/disable-mobile-data.sh 1970-01-01 00:00:00 +0000 | |||
78 | +++ scripts/disable-mobile-data.sh 2016-04-26 11:24:03 +0000 | |||
79 | @@ -0,0 +1,8 @@ | |||
80 | 1 | dbus-send --session --print-reply \ | ||
81 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
82 | 3 | /com/ubuntu/connectivity1/Private \ | ||
83 | 4 | org.freedesktop.DBus.Properties.Set \ | ||
84 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
85 | 6 | string:MobileDataEnabled \ | ||
86 | 7 | variant:boolean:false | ||
87 | 8 | sh get-mobile-data-enabled.sh | ||
88 | 0 | 9 | ||
89 | === added file 'scripts/enable-mobile-data.sh' | |||
90 | --- scripts/enable-mobile-data.sh 1970-01-01 00:00:00 +0000 | |||
91 | +++ scripts/enable-mobile-data.sh 2016-04-26 11:24:03 +0000 | |||
92 | @@ -0,0 +1,8 @@ | |||
93 | 1 | dbus-send --session --print-reply \ | ||
94 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
95 | 3 | /com/ubuntu/connectivity1/Private \ | ||
96 | 4 | org.freedesktop.DBus.Properties.Set \ | ||
97 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
98 | 6 | string:MobileDataEnabled \ | ||
99 | 7 | variant:boolean:true | ||
100 | 8 | sh get-mobile-data-enabled.sh | ||
101 | 0 | 9 | ||
102 | === added file 'scripts/get-mobile-data-enabled.sh' | |||
103 | --- scripts/get-mobile-data-enabled.sh 1970-01-01 00:00:00 +0000 | |||
104 | +++ scripts/get-mobile-data-enabled.sh 2016-04-26 11:24:03 +0000 | |||
105 | @@ -0,0 +1,6 @@ | |||
106 | 1 | dbus-send --session --print-reply \ | ||
107 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
108 | 3 | /com/ubuntu/connectivity1/Private \ | ||
109 | 4 | org.freedesktop.DBus.Properties.Get \ | ||
110 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
111 | 6 | string:MobileDataEnabled | ||
112 | 0 | 7 | ||
113 | === added file 'scripts/get-modems.sh' | |||
114 | --- scripts/get-modems.sh 1970-01-01 00:00:00 +0000 | |||
115 | +++ scripts/get-modems.sh 2016-04-26 11:24:03 +0000 | |||
116 | @@ -0,0 +1,6 @@ | |||
117 | 1 | dbus-send --session --print-reply \ | ||
118 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
119 | 3 | /com/ubuntu/connectivity1/Private \ | ||
120 | 4 | org.freedesktop.DBus.Properties.Get \ | ||
121 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
122 | 6 | string:Modems | ||
123 | 0 | 7 | ||
124 | === added file 'scripts/get-sim-for-mobile-data.sh' | |||
125 | --- scripts/get-sim-for-mobile-data.sh 1970-01-01 00:00:00 +0000 | |||
126 | +++ scripts/get-sim-for-mobile-data.sh 2016-04-26 11:24:03 +0000 | |||
127 | @@ -0,0 +1,6 @@ | |||
128 | 1 | dbus-send --session --print-reply \ | ||
129 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
130 | 3 | /com/ubuntu/connectivity1/Private \ | ||
131 | 4 | org.freedesktop.DBus.Properties.Get \ | ||
132 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
133 | 6 | string:SimForMobileData | ||
134 | 0 | 7 | ||
135 | === added file 'scripts/get-sims.sh' | |||
136 | --- scripts/get-sims.sh 1970-01-01 00:00:00 +0000 | |||
137 | +++ scripts/get-sims.sh 2016-04-26 11:24:03 +0000 | |||
138 | @@ -0,0 +1,6 @@ | |||
139 | 1 | dbus-send --session --print-reply \ | ||
140 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
141 | 3 | /com/ubuntu/connectivity1/Private \ | ||
142 | 4 | org.freedesktop.DBus.Properties.Get \ | ||
143 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
144 | 6 | string:Sims | ||
145 | 0 | 7 | ||
146 | === added file 'scripts/monitor-private-properties.sh' | |||
147 | --- scripts/monitor-private-properties.sh 1970-01-01 00:00:00 +0000 | |||
148 | +++ scripts/monitor-private-properties.sh 2016-04-26 11:24:03 +0000 | |||
149 | @@ -0,0 +1,7 @@ | |||
150 | 1 | dbus-monitor --session \ | ||
151 | 2 | "type=signal, | ||
152 | 3 | sender='com.ubuntu.connectivity1', | ||
153 | 4 | path=/com/ubuntu/connectivity1/Private, | ||
154 | 5 | interface=org.freedesktop.DBus.Properties, | ||
155 | 6 | member=PropertiesChanged" | ||
156 | 7 | |||
157 | 0 | 8 | ||
158 | === added file 'scripts/set-sim-for-mobile-data.sh' | |||
159 | --- scripts/set-sim-for-mobile-data.sh 1970-01-01 00:00:00 +0000 | |||
160 | +++ scripts/set-sim-for-mobile-data.sh 2016-04-26 11:24:03 +0000 | |||
161 | @@ -0,0 +1,8 @@ | |||
162 | 1 | dbus-send --session --print-reply \ | ||
163 | 2 | --dest=com.ubuntu.connectivity1 \ | ||
164 | 3 | /com/ubuntu/connectivity1/Private \ | ||
165 | 4 | org.freedesktop.DBus.Properties.Set \ | ||
166 | 5 | string:com.ubuntu.connectivity1.Private \ | ||
167 | 6 | string:SimForMobileData \ | ||
168 | 7 | variant:objpath:$1 | ||
169 | 8 | sh get-sim-for-mobile-data.sh | ||
170 | 0 | 9 | ||
171 | === modified file 'src/connectivity-api/connectivity-qml/CMakeLists.txt' | |||
172 | --- src/connectivity-api/connectivity-qml/CMakeLists.txt 2015-05-19 13:49:21 +0000 | |||
173 | +++ src/connectivity-api/connectivity-qml/CMakeLists.txt 2016-04-26 11:24:03 +0000 | |||
174 | @@ -8,7 +8,7 @@ | |||
175 | 8 | ) | 8 | ) |
176 | 9 | 9 | ||
177 | 10 | set(CONNECTIVITY_QML_SRC | 10 | set(CONNECTIVITY_QML_SRC |
179 | 11 | plugin.cpp | 11 | plugin.cpp |
180 | 12 | ) | 12 | ) |
181 | 13 | 13 | ||
182 | 14 | add_library(connectivity-qml SHARED | 14 | add_library(connectivity-qml SHARED |
183 | 15 | 15 | ||
184 | === modified file 'src/connectivity-api/connectivity-qml/plugin.cpp' | |||
185 | --- src/connectivity-api/connectivity-qml/plugin.cpp 2015-12-04 13:18:04 +0000 | |||
186 | +++ src/connectivity-api/connectivity-qml/plugin.cpp 2016-04-26 11:24:03 +0000 | |||
187 | @@ -21,6 +21,13 @@ | |||
188 | 21 | #include <connectivityqt/connectivity.h> | 21 | #include <connectivityqt/connectivity.h> |
189 | 22 | #include <connectivityqt/openvpn-connection.h> | 22 | #include <connectivityqt/openvpn-connection.h> |
190 | 23 | 23 | ||
191 | 24 | #include <connectivityqt/path.h> | ||
192 | 25 | #include <connectivityqt/sim.h> | ||
193 | 26 | |||
194 | 27 | #include <connectivityqt/modems-list-model.h> | ||
195 | 28 | #include <connectivityqt/sims-list-model.h> | ||
196 | 29 | |||
197 | 30 | |||
198 | 24 | #include <QtQml> | 31 | #include <QtQml> |
199 | 25 | 32 | ||
200 | 26 | namespace | 33 | namespace |
201 | @@ -44,10 +51,16 @@ | |||
202 | 44 | { | 51 | { |
203 | 45 | connectivityqt::Connectivity::registerMetaTypes(); | 52 | connectivityqt::Connectivity::registerMetaTypes(); |
204 | 46 | qmlRegisterSingletonType<connectivityqt::Connectivity>(uri, 1, 0, "NetworkingStatus", connectivitySingletonProvider); | 53 | qmlRegisterSingletonType<connectivityqt::Connectivity>(uri, 1, 0, "NetworkingStatus", connectivitySingletonProvider); |
206 | 47 | qmlRegisterSingletonType<connectivityqt::Connectivity>(uri, 1, 0, "Connectivity", connectivitySingletonProvider); | 54 | qmlRegisterSingletonType<connectivityqt::Connectivity>(uri, 1, 1, "Connectivity", connectivitySingletonProvider); |
207 | 48 | qmlRegisterUncreatableType<connectivityqt::VpnConnectionsListModel>(uri, 1, 0, "VpnConnectionsListModel", "Access VpnConnectionsListModel via Connectivity object"); | 55 | qmlRegisterUncreatableType<connectivityqt::VpnConnectionsListModel>(uri, 1, 0, "VpnConnectionsListModel", "Access VpnConnectionsListModel via Connectivity object"); |
208 | 49 | qmlRegisterUncreatableType<connectivityqt::VpnConnection>(uri, 1, 0, "VpnConnection", "Access VpnConnection via VpnConnectionsListModel object"); | 56 | qmlRegisterUncreatableType<connectivityqt::VpnConnection>(uri, 1, 0, "VpnConnection", "Access VpnConnection via VpnConnectionsListModel object"); |
209 | 50 | qmlRegisterUncreatableType<connectivityqt::OpenvpnConnection>(uri, 1, 0, "OpenvpnConnection", "Access OpenvpnConnection via VpnConnectionsListModel object"); | 57 | qmlRegisterUncreatableType<connectivityqt::OpenvpnConnection>(uri, 1, 0, "OpenvpnConnection", "Access OpenvpnConnection via VpnConnectionsListModel object"); |
210 | 58 | |||
211 | 59 | qmlRegisterUncreatableType<connectivityqt::Path>(uri, 1, 1, "Path", ""); | ||
212 | 60 | qmlRegisterUncreatableType<connectivityqt::Sim>(uri, 1, 1, "Sim", ""); | ||
213 | 61 | |||
214 | 62 | qmlRegisterUncreatableType<connectivityqt::ModemsListModel>(uri, 1, 1, "ModemsListModel", ""); | ||
215 | 63 | qmlRegisterUncreatableType<connectivityqt::ModemsListModel>(uri, 1, 1, "SimsListModel", ""); | ||
216 | 51 | } | 64 | } |
217 | 52 | 65 | ||
218 | 53 | void | 66 | void |
219 | 54 | 67 | ||
220 | === added file 'src/connectivity-api/connectivity-qml/proxy-model.cpp' | |||
221 | === added file 'src/connectivity-api/connectivity-qml/proxy-model.h' | |||
222 | --- src/connectivity-api/connectivity-qml/proxy-model.h 1970-01-01 00:00:00 +0000 | |||
223 | +++ src/connectivity-api/connectivity-qml/proxy-model.h 2016-04-26 11:24:03 +0000 | |||
224 | @@ -0,0 +1,80 @@ | |||
225 | 1 | /* | ||
226 | 2 | * Copyright © 2016 Canonical Ltd. | ||
227 | 3 | * | ||
228 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
229 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
230 | 6 | * as published by the Free Software Foundation. | ||
231 | 7 | * | ||
232 | 8 | * This program is distributed in the hope that it will be useful, | ||
233 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
234 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
235 | 11 | * GNU Lesser General Public License for more details. | ||
236 | 12 | * | ||
237 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
238 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
239 | 15 | * | ||
240 | 16 | * Authors: | ||
241 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
242 | 18 | */ | ||
243 | 19 | |||
244 | 20 | #pragma once | ||
245 | 21 | |||
246 | 22 | #include <QAbstractItemModel> | ||
247 | 23 | #include <QDBusConnection> | ||
248 | 24 | #include <QDBusObjectPath> | ||
249 | 25 | |||
250 | 26 | #include <memory> | ||
251 | 27 | |||
252 | 28 | namespace connectivityqt | ||
253 | 29 | { | ||
254 | 30 | |||
255 | 31 | class Q_DECL_EXPORT ModemsListModel : public QAbstractListModel | ||
256 | 32 | { | ||
257 | 33 | Q_OBJECT | ||
258 | 34 | |||
259 | 35 | Q_ENUMS(Roles) | ||
260 | 36 | |||
261 | 37 | public: | ||
262 | 38 | |||
263 | 39 | enum Roles | ||
264 | 40 | { | ||
265 | 41 | RoleIndex = Qt::UserRole + 1, | ||
266 | 42 | RoleSerial, | ||
267 | 43 | RoleSimPath | ||
268 | 44 | }; | ||
269 | 45 | |||
270 | 46 | ModemsListModel(const QDBusConnection &connection, QObject *parent); | ||
271 | 47 | |||
272 | 48 | ~ModemsListModel(); | ||
273 | 49 | |||
274 | 50 | int columnCount(const QModelIndex &parent) const override; | ||
275 | 51 | |||
276 | 52 | int rowCount(const QModelIndex &parent) const override; | ||
277 | 53 | |||
278 | 54 | QVariant data(const QModelIndex &index, int role) const override; | ||
279 | 55 | |||
280 | 56 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; | ||
281 | 57 | |||
282 | 58 | Qt::ItemFlags flags(const QModelIndex & index) const override; | ||
283 | 59 | |||
284 | 60 | QHash<int, QByteArray> roleNames() const override | ||
285 | 61 | { | ||
286 | 62 | QHash<int, QByteArray> roles; | ||
287 | 63 | roles[RoleIndex] = "Index"; | ||
288 | 64 | roles[RoleSerial] = "Serial"; | ||
289 | 65 | roles[RoleSimPath] = "SimPath"; | ||
290 | 66 | return roles; | ||
291 | 67 | } | ||
292 | 68 | |||
293 | 69 | void updateModemDBusPaths(QList<QDBusObjectPath> values); | ||
294 | 70 | |||
295 | 71 | public Q_SLOTS: | ||
296 | 72 | |||
297 | 73 | Q_SIGNALS: | ||
298 | 74 | |||
299 | 75 | protected: | ||
300 | 76 | class Priv; | ||
301 | 77 | std::shared_ptr<Priv> d; | ||
302 | 78 | }; | ||
303 | 79 | |||
304 | 80 | } | ||
305 | 0 | 81 | ||
306 | === modified file 'src/connectivity-api/connectivity-qt/CMakeLists.txt' | |||
307 | --- src/connectivity-api/connectivity-qt/CMakeLists.txt 2016-02-17 10:58:27 +0000 | |||
308 | +++ src/connectivity-api/connectivity-qt/CMakeLists.txt 2016-04-26 11:24:03 +0000 | |||
309 | @@ -22,6 +22,11 @@ | |||
310 | 22 | CONNECTIVITY_QT_SRC | 22 | CONNECTIVITY_QT_SRC |
311 | 23 | connectivityqt/internal/dbus-property-cache.cpp | 23 | connectivityqt/internal/dbus-property-cache.cpp |
312 | 24 | connectivityqt/connectivity.cpp | 24 | connectivityqt/connectivity.cpp |
313 | 25 | connectivityqt/modem.cpp | ||
314 | 26 | connectivityqt/modems-list-model.cpp | ||
315 | 27 | connectivityqt/sim.cpp | ||
316 | 28 | connectivityqt/sims-list-model.cpp | ||
317 | 29 | connectivityqt/path.cpp | ||
318 | 25 | connectivityqt/openvpn-connection.cpp | 30 | connectivityqt/openvpn-connection.cpp |
319 | 26 | connectivityqt/pptp-connection.cpp | 31 | connectivityqt/pptp-connection.cpp |
320 | 27 | connectivityqt/vpn-connection.cpp | 32 | connectivityqt/vpn-connection.cpp |
321 | @@ -33,6 +38,8 @@ | |||
322 | 33 | "${DATA_DIR}/org.freedesktop.DBus.Properties.xml" | 38 | "${DATA_DIR}/org.freedesktop.DBus.Properties.xml" |
323 | 34 | "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml" | 39 | "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml" |
324 | 35 | "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml" | 40 | "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml" |
325 | 41 | "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml" | ||
326 | 42 | "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml" | ||
327 | 36 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml" | 43 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml" |
328 | 37 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.OpenVpn.xml" | 44 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.OpenVpn.xml" |
329 | 38 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.Pptp.xml" | 45 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.Pptp.xml" |
330 | @@ -54,6 +61,18 @@ | |||
331 | 54 | 61 | ||
332 | 55 | qt5_add_dbus_interface( | 62 | qt5_add_dbus_interface( |
333 | 56 | CONNECTIVITY_QT_SRC | 63 | CONNECTIVITY_QT_SRC |
334 | 64 | "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml" | ||
335 | 65 | ModemInterface | ||
336 | 66 | ) | ||
337 | 67 | |||
338 | 68 | qt5_add_dbus_interface( | ||
339 | 69 | CONNECTIVITY_QT_SRC | ||
340 | 70 | "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml" | ||
341 | 71 | SimInterface | ||
342 | 72 | ) | ||
343 | 73 | |||
344 | 74 | qt5_add_dbus_interface( | ||
345 | 75 | CONNECTIVITY_QT_SRC | ||
346 | 57 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml" | 76 | "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml" |
347 | 58 | VpnConnectionInterface | 77 | VpnConnectionInterface |
348 | 59 | ) | 78 | ) |
349 | @@ -99,8 +118,8 @@ | |||
350 | 99 | ${CONNECTIVITY_QT_LIB_TARGET} | 118 | ${CONNECTIVITY_QT_LIB_TARGET} |
351 | 100 | PROPERTIES | 119 | PROPERTIES |
352 | 101 | SOVERSION ${SO_VERSION} | 120 | SOVERSION ${SO_VERSION} |
355 | 102 | LINK_FLAGS "-Wl,--version-script,${SYMBOL_MAP}" | 121 | # LINK_FLAGS "-Wl,--version-script,${SYMBOL_MAP}" |
356 | 103 | LINK_DEPENDS "${SYMBOL_MAP}" | 122 | # LINK_DEPENDS "${SYMBOL_MAP}" |
357 | 104 | ) | 123 | ) |
358 | 105 | 124 | ||
359 | 106 | install( | 125 | install( |
360 | 107 | 126 | ||
361 | === modified file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp' | |||
362 | --- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 2015-12-04 13:18:04 +0000 | |||
363 | +++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 2016-04-26 11:24:03 +0000 | |||
364 | @@ -20,6 +20,8 @@ | |||
365 | 20 | #include <connectivityqt/connectivity.h> | 20 | #include <connectivityqt/connectivity.h> |
366 | 21 | #include <connectivityqt/internal/vpn-connection-list-model-parameters.h> | 21 | #include <connectivityqt/internal/vpn-connection-list-model-parameters.h> |
367 | 22 | #include <connectivityqt/vpn-connections-list-model.h> | 22 | #include <connectivityqt/vpn-connections-list-model.h> |
368 | 23 | #include <connectivityqt/modems-list-model.h> | ||
369 | 24 | #include <connectivityqt/sims-list-model.h> | ||
370 | 23 | #include <dbus-types.h> | 25 | #include <dbus-types.h> |
371 | 24 | #include <NetworkingStatusInterface.h> | 26 | #include <NetworkingStatusInterface.h> |
372 | 25 | #include <NetworkingStatusPrivateInterface.h> | 27 | #include <NetworkingStatusPrivateInterface.h> |
373 | @@ -57,6 +59,11 @@ | |||
374 | 57 | 59 | ||
375 | 58 | VpnConnectionsListModel::SPtr m_vpnConnectionsModel; | 60 | VpnConnectionsListModel::SPtr m_vpnConnectionsModel; |
376 | 59 | 61 | ||
377 | 62 | SimsListModel *m_simsModel; | ||
378 | 63 | ModemsListModel *m_modemsModel; | ||
379 | 64 | |||
380 | 65 | Sim *m_simForMobileData = nullptr; | ||
381 | 66 | |||
382 | 60 | static QVector<Limitations> toLimitations(const QVariant& value) | 67 | static QVector<Limitations> toLimitations(const QVariant& value) |
383 | 61 | { | 68 | { |
384 | 62 | auto l = value.toStringList(); | 69 | auto l = value.toStringList(); |
385 | @@ -100,6 +107,8 @@ | |||
386 | 100 | { | 107 | { |
387 | 101 | Q_EMIT p.initialized(); | 108 | Q_EMIT p.initialized(); |
388 | 102 | } | 109 | } |
389 | 110 | QList<QDBusObjectPath> tmp; | ||
390 | 111 | qvariant_cast<QDBusArgument>(m_writePropertyCache->get("Modems")) >> tmp; | ||
391 | 103 | } | 112 | } |
392 | 104 | 113 | ||
393 | 105 | void propertyChanged(const QString& name, const QVariant& value) | 114 | void propertyChanged(const QString& name, const QVariant& value) |
394 | @@ -164,6 +173,29 @@ | |||
395 | 164 | { | 173 | { |
396 | 165 | Q_EMIT p.hotspotStoredUpdated(value.toBool()); | 174 | Q_EMIT p.hotspotStoredUpdated(value.toBool()); |
397 | 166 | } | 175 | } |
398 | 176 | else if (name == "MobileDataEnabled") | ||
399 | 177 | { | ||
400 | 178 | Q_EMIT p.mobileDataEnabledUpdated(value.toBool()); | ||
401 | 179 | } | ||
402 | 180 | else if (name == "SimForMobileData") | ||
403 | 181 | { | ||
404 | 182 | auto path = value.value<QDBusObjectPath>(); | ||
405 | 183 | auto sim = m_simsModel->getSimByPath(path); | ||
406 | 184 | p.setSimForMobileData(sim); | ||
407 | 185 | } | ||
408 | 186 | else if (name == "Modems") | ||
409 | 187 | { | ||
410 | 188 | QList<QDBusObjectPath> tmp; | ||
411 | 189 | qvariant_cast<QDBusArgument>(m_writePropertyCache->get("Modems")) >> tmp; | ||
412 | 190 | m_modemsModel->updateModemDBusPaths(tmp); | ||
413 | 191 | } | ||
414 | 192 | else if (name == "Sims") | ||
415 | 193 | { | ||
416 | 194 | QList<QDBusObjectPath> tmp; | ||
417 | 195 | qvariant_cast<QDBusArgument>(m_writePropertyCache->get("Sims")) >> tmp; | ||
418 | 196 | m_simsModel->updateSimDBusPaths(tmp); | ||
419 | 197 | } | ||
420 | 198 | |||
421 | 167 | } | 199 | } |
422 | 168 | 200 | ||
423 | 169 | }; | 201 | }; |
424 | @@ -178,6 +210,8 @@ | |||
425 | 178 | 210 | ||
426 | 179 | qRegisterMetaType<connectivityqt::VpnConnection*>("VpnConnection*"); | 211 | qRegisterMetaType<connectivityqt::VpnConnection*>("VpnConnection*"); |
427 | 180 | qRegisterMetaType<connectivityqt::VpnConnection::Type>("VpnConnection::Type"); | 212 | qRegisterMetaType<connectivityqt::VpnConnection::Type>("VpnConnection::Type"); |
428 | 213 | |||
429 | 214 | qRegisterMetaType<connectivityqt::Sim*>("Sim*"); | ||
430 | 181 | } | 215 | } |
431 | 182 | 216 | ||
432 | 183 | Connectivity::Connectivity(const QDBusConnection& sessionConnection, QObject* parent) : | 217 | Connectivity::Connectivity(const QDBusConnection& sessionConnection, QObject* parent) : |
433 | @@ -196,6 +230,9 @@ | |||
434 | 196 | { | 230 | { |
435 | 197 | d->m_objectOwner = objectOwner; | 231 | d->m_objectOwner = objectOwner; |
436 | 198 | 232 | ||
437 | 233 | d->m_simsModel = new SimsListModel(sessionConnection, this); | ||
438 | 234 | d->m_modemsModel = new ModemsListModel(sessionConnection, d->m_simsModel, this); | ||
439 | 235 | |||
440 | 199 | d->m_readInterface = make_shared< | 236 | d->m_readInterface = make_shared< |
441 | 200 | ComUbuntuConnectivity1NetworkingStatusInterface>( | 237 | ComUbuntuConnectivity1NetworkingStatusInterface>( |
442 | 201 | DBusTypes::DBUS_NAME, DBusTypes::SERVICE_PATH, | 238 | DBusTypes::DBUS_NAME, DBusTypes::SERVICE_PATH, |
443 | @@ -225,6 +262,17 @@ | |||
444 | 225 | &internal::DBusPropertyCache::initialized, d.get(), | 262 | &internal::DBusPropertyCache::initialized, d.get(), |
445 | 226 | &Connectivity::Priv::interfaceInitialized); | 263 | &Connectivity::Priv::interfaceInitialized); |
446 | 227 | 264 | ||
447 | 265 | if (d->m_writePropertyCache->isInitialized()) { | ||
448 | 266 | QList<QDBusObjectPath> tmp; | ||
449 | 267 | qvariant_cast<QDBusArgument>(d->m_writePropertyCache->get("Sims")) >> tmp; | ||
450 | 268 | d->m_simsModel->updateSimDBusPaths(tmp); | ||
451 | 269 | tmp.clear(); | ||
452 | 270 | qvariant_cast<QDBusArgument>(d->m_writePropertyCache->get("Modems")) >> tmp; | ||
453 | 271 | d->m_modemsModel->updateModemDBusPaths(tmp); | ||
454 | 272 | |||
455 | 273 | d->m_simForMobileData = d->m_simsModel->getSimByPath(d->m_writePropertyCache->get("SimForMobileData").value<QDBusObjectPath>()); | ||
456 | 274 | } | ||
457 | 275 | |||
458 | 228 | connect(d->m_writeInterface.get(), | 276 | connect(d->m_writeInterface.get(), |
459 | 229 | &ComUbuntuConnectivity1PrivateInterface::ReportError, this, | 277 | &ComUbuntuConnectivity1PrivateInterface::ReportError, this, |
460 | 230 | &Connectivity::reportError); | 278 | &Connectivity::reportError); |
461 | @@ -384,6 +432,50 @@ | |||
462 | 384 | return d->m_vpnConnectionsModel.get(); | 432 | return d->m_vpnConnectionsModel.get(); |
463 | 385 | } | 433 | } |
464 | 386 | 434 | ||
465 | 435 | bool Connectivity::mobileDataEnabled() const | ||
466 | 436 | { | ||
467 | 437 | return d->m_writePropertyCache->get("MobileDataEnabled").toBool(); | ||
468 | 438 | } | ||
469 | 439 | |||
470 | 440 | void Connectivity::setMobileDataEnabled(bool enabled) | ||
471 | 441 | { | ||
472 | 442 | d->m_writeInterface->setMobileDataEnabled(enabled); | ||
473 | 443 | } | ||
474 | 444 | |||
475 | 445 | Sim *Connectivity::simForMobileData() const | ||
476 | 446 | { | ||
477 | 447 | return d->m_simForMobileData; | ||
478 | 448 | } | ||
479 | 449 | |||
480 | 450 | void Connectivity::setSimForMobileData(Sim *sim) | ||
481 | 451 | { | ||
482 | 452 | if (d->m_simForMobileData == sim) | ||
483 | 453 | { | ||
484 | 454 | return; | ||
485 | 455 | } | ||
486 | 456 | d->m_simForMobileData = sim; | ||
487 | 457 | if (sim) | ||
488 | 458 | { | ||
489 | 459 | d->m_writeInterface->setSimForMobileData(sim->path()); | ||
490 | 460 | } | ||
491 | 461 | else | ||
492 | 462 | { | ||
493 | 463 | d->m_writeInterface->setSimForMobileData(QDBusObjectPath("/")); | ||
494 | 464 | } | ||
495 | 465 | Q_EMIT simForMobileDataUpdated(sim); | ||
496 | 466 | } | ||
497 | 467 | |||
498 | 468 | QAbstractItemModel* Connectivity::modems() const | ||
499 | 469 | { | ||
500 | 470 | return d->m_modemsModel; | ||
501 | 471 | } | ||
502 | 472 | |||
503 | 473 | QAbstractItemModel *Connectivity::sims() const | ||
504 | 474 | { | ||
505 | 475 | return d->m_simsModel; | ||
506 | 476 | } | ||
507 | 477 | |||
508 | 478 | |||
509 | 387 | } | 479 | } |
510 | 388 | 480 | ||
511 | 389 | #include "connectivity.moc" | 481 | #include "connectivity.moc" |
512 | 390 | 482 | ||
513 | === modified file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h' | |||
514 | --- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 2016-01-14 13:38:38 +0000 | |||
515 | +++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 2016-04-26 11:24:03 +0000 | |||
516 | @@ -30,9 +30,13 @@ | |||
517 | 30 | 30 | ||
518 | 31 | #include <connectivityqt/vpn-connections-list-model.h> | 31 | #include <connectivityqt/vpn-connections-list-model.h> |
519 | 32 | 32 | ||
520 | 33 | #include <QDBusObjectPath> | ||
521 | 34 | |||
522 | 33 | namespace connectivityqt | 35 | namespace connectivityqt |
523 | 34 | { | 36 | { |
524 | 35 | 37 | ||
525 | 38 | class Sim; | ||
526 | 39 | |||
527 | 36 | class Q_DECL_EXPORT Connectivity: public QObject | 40 | class Q_DECL_EXPORT Connectivity: public QObject |
528 | 37 | { | 41 | { |
529 | 38 | Q_OBJECT | 42 | Q_OBJECT |
530 | @@ -138,6 +142,18 @@ | |||
531 | 138 | Q_PROPERTY(QAbstractItemModel* vpnConnections READ vpnConnections NOTIFY vpnConnectionsUpdated) | 142 | Q_PROPERTY(QAbstractItemModel* vpnConnections READ vpnConnections NOTIFY vpnConnectionsUpdated) |
532 | 139 | QAbstractItemModel* vpnConnections() const; | 143 | QAbstractItemModel* vpnConnections() const; |
533 | 140 | 144 | ||
534 | 145 | Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledUpdated) | ||
535 | 146 | bool mobileDataEnabled() const; | ||
536 | 147 | |||
537 | 148 | Q_PROPERTY(Sim* simForMobileData READ simForMobileData WRITE setSimForMobileData NOTIFY simForMobileDataUpdated) | ||
538 | 149 | Sim* simForMobileData() const; | ||
539 | 150 | |||
540 | 151 | Q_PROPERTY(QAbstractItemModel* modems READ modems CONSTANT) | ||
541 | 152 | QAbstractItemModel* modems() const; | ||
542 | 153 | |||
543 | 154 | Q_PROPERTY(QAbstractItemModel* sims READ sims CONSTANT) | ||
544 | 155 | QAbstractItemModel* sims() const; | ||
545 | 156 | |||
546 | 141 | public Q_SLOTS: | 157 | public Q_SLOTS: |
547 | 142 | void setFlightMode(bool enabled); | 158 | void setFlightMode(bool enabled); |
548 | 143 | 159 | ||
549 | @@ -153,6 +169,10 @@ | |||
550 | 153 | 169 | ||
551 | 154 | void setHotspotAuth(const QString& auth); | 170 | void setHotspotAuth(const QString& auth); |
552 | 155 | 171 | ||
553 | 172 | void setMobileDataEnabled(bool enabled); | ||
554 | 173 | |||
555 | 174 | void setSimForMobileData(Sim *sim); | ||
556 | 175 | |||
557 | 156 | Q_SIGNALS: | 176 | Q_SIGNALS: |
558 | 157 | void flightModeUpdated(bool); | 177 | void flightModeUpdated(bool); |
559 | 158 | 178 | ||
560 | @@ -194,6 +214,10 @@ | |||
561 | 194 | 214 | ||
562 | 195 | void vpnConnectionsUpdated(QAbstractItemModel*); | 215 | void vpnConnectionsUpdated(QAbstractItemModel*); |
563 | 196 | 216 | ||
564 | 217 | void mobileDataEnabledUpdated(bool); | ||
565 | 218 | |||
566 | 219 | void simForMobileDataUpdated(Sim* sim); | ||
567 | 220 | |||
568 | 197 | protected: | 221 | protected: |
569 | 198 | class Priv; | 222 | class Priv; |
570 | 199 | std::shared_ptr<Priv> d; | 223 | std::shared_ptr<Priv> d; |
571 | 200 | 224 | ||
572 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp' | |||
573 | --- src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp 1970-01-01 00:00:00 +0000 | |||
574 | +++ src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp 2016-04-26 11:24:03 +0000 | |||
575 | @@ -0,0 +1,112 @@ | |||
576 | 1 | /* | ||
577 | 2 | * Copyright © 2016 Canonical Ltd. | ||
578 | 3 | * | ||
579 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
580 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
581 | 6 | * as published by the Free Software Foundation. | ||
582 | 7 | * | ||
583 | 8 | * This program is distributed in the hope that it will be useful, | ||
584 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
585 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
586 | 11 | * GNU Lesser General Public License for more details. | ||
587 | 12 | * | ||
588 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
589 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
590 | 15 | * | ||
591 | 16 | * Authors: | ||
592 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
593 | 18 | */ | ||
594 | 19 | |||
595 | 20 | #include <connectivityqt/internal/dbus-property-cache.h> | ||
596 | 21 | #include <connectivityqt/modem.h> | ||
597 | 22 | #include <dbus-types.h> | ||
598 | 23 | |||
599 | 24 | #include <ModemInterface.h> | ||
600 | 25 | |||
601 | 26 | using namespace std; | ||
602 | 27 | |||
603 | 28 | namespace connectivityqt | ||
604 | 29 | { | ||
605 | 30 | |||
606 | 31 | class Modem::Priv: public QObject | ||
607 | 32 | { | ||
608 | 33 | Q_OBJECT | ||
609 | 34 | |||
610 | 35 | public: | ||
611 | 36 | Priv(Modem& parent) : | ||
612 | 37 | p(parent) | ||
613 | 38 | { | ||
614 | 39 | } | ||
615 | 40 | |||
616 | 41 | public Q_SLOTS: | ||
617 | 42 | void propertyChanged(const QString& name, const QVariant& value) | ||
618 | 43 | { | ||
619 | 44 | if (name == "Sim") | ||
620 | 45 | { | ||
621 | 46 | m_sim = m_sims->getSimByPath(value.value<QDBusObjectPath>()); | ||
622 | 47 | Q_EMIT p.simChanged(m_sim); | ||
623 | 48 | } | ||
624 | 49 | } | ||
625 | 50 | |||
626 | 51 | public: | ||
627 | 52 | Modem& p; | ||
628 | 53 | |||
629 | 54 | Sim *m_sim; | ||
630 | 55 | SimsListModel *m_sims; | ||
631 | 56 | |||
632 | 57 | unique_ptr<ComUbuntuConnectivity1ModemInterface> m_modemInterface; | ||
633 | 58 | |||
634 | 59 | internal::DBusPropertyCache::UPtr m_propertyCache; | ||
635 | 60 | }; | ||
636 | 61 | |||
637 | 62 | Modem::Modem(const QDBusObjectPath& path, | ||
638 | 63 | const QDBusConnection& connection, | ||
639 | 64 | SimsListModel *sims, | ||
640 | 65 | QObject* parent) : | ||
641 | 66 | QObject(parent), d(new Priv(*this)) | ||
642 | 67 | { | ||
643 | 68 | d->m_sims = sims; | ||
644 | 69 | d->m_modemInterface = make_unique< | ||
645 | 70 | ComUbuntuConnectivity1ModemInterface>( | ||
646 | 71 | DBusTypes::DBUS_NAME, path.path(), connection); | ||
647 | 72 | |||
648 | 73 | d->m_propertyCache = | ||
649 | 74 | make_unique<internal::DBusPropertyCache>( | ||
650 | 75 | DBusTypes::DBUS_NAME, | ||
651 | 76 | ComUbuntuConnectivity1ModemInterface::staticInterfaceName(), | ||
652 | 77 | path.path(), connection); | ||
653 | 78 | |||
654 | 79 | connect(d->m_propertyCache.get(), | ||
655 | 80 | &internal::DBusPropertyCache::propertyChanged, d.get(), | ||
656 | 81 | &Priv::propertyChanged); | ||
657 | 82 | |||
658 | 83 | d->m_sim = d->m_sims->getSimByPath(d->m_propertyCache->get("Sim").value<QDBusObjectPath>()); | ||
659 | 84 | } | ||
660 | 85 | |||
661 | 86 | Modem::~Modem() | ||
662 | 87 | { | ||
663 | 88 | } | ||
664 | 89 | |||
665 | 90 | QDBusObjectPath Modem::path() const | ||
666 | 91 | { | ||
667 | 92 | return QDBusObjectPath(d->m_modemInterface->path()); | ||
668 | 93 | } | ||
669 | 94 | |||
670 | 95 | int Modem::index() const | ||
671 | 96 | { | ||
672 | 97 | return d->m_propertyCache->get("Index").toInt(); | ||
673 | 98 | } | ||
674 | 99 | |||
675 | 100 | Sim *Modem::sim() const | ||
676 | 101 | { | ||
677 | 102 | return d->m_sim; | ||
678 | 103 | } | ||
679 | 104 | |||
680 | 105 | QString Modem::serial() const | ||
681 | 106 | { | ||
682 | 107 | return d->m_propertyCache->get("Serial").toString(); | ||
683 | 108 | } | ||
684 | 109 | |||
685 | 110 | } | ||
686 | 111 | |||
687 | 112 | #include "modem.moc" | ||
688 | 0 | 113 | ||
689 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/modem.h' | |||
690 | --- src/connectivity-api/connectivity-qt/connectivityqt/modem.h 1970-01-01 00:00:00 +0000 | |||
691 | +++ src/connectivity-api/connectivity-qt/connectivityqt/modem.h 2016-04-26 11:24:03 +0000 | |||
692 | @@ -0,0 +1,68 @@ | |||
693 | 1 | /* | ||
694 | 2 | * Copyright © 2016 Canonical Ltd. | ||
695 | 3 | * | ||
696 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
697 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
698 | 6 | * as published by the Free Software Foundation. | ||
699 | 7 | * | ||
700 | 8 | * This program is distributed in the hope that it will be useful, | ||
701 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
702 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
703 | 11 | * GNU Lesser General Public License for more details. | ||
704 | 12 | * | ||
705 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
706 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
707 | 15 | * | ||
708 | 16 | * Authors: | ||
709 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
710 | 18 | */ | ||
711 | 19 | |||
712 | 20 | #pragma once | ||
713 | 21 | |||
714 | 22 | #include <QDBusConnection> | ||
715 | 23 | #include <QDBusObjectPath> | ||
716 | 24 | #include <QObject> | ||
717 | 25 | |||
718 | 26 | #include <unity/util/DefinesPtrs.h> | ||
719 | 27 | #include <connectivityqt/sims-list-model.h> | ||
720 | 28 | |||
721 | 29 | namespace connectivityqt | ||
722 | 30 | { | ||
723 | 31 | |||
724 | 32 | class Q_DECL_EXPORT Modem : public QObject | ||
725 | 33 | { | ||
726 | 34 | Q_OBJECT | ||
727 | 35 | |||
728 | 36 | public: | ||
729 | 37 | UNITY_DEFINES_PTRS(Modem); | ||
730 | 38 | |||
731 | 39 | Modem(const QDBusObjectPath& path, | ||
732 | 40 | const QDBusConnection& connection, | ||
733 | 41 | SimsListModel *sims, | ||
734 | 42 | QObject* parent = 0); | ||
735 | 43 | |||
736 | 44 | virtual ~Modem(); | ||
737 | 45 | |||
738 | 46 | Q_PROPERTY(QDBusObjectPath path READ path) | ||
739 | 47 | QDBusObjectPath path() const; | ||
740 | 48 | |||
741 | 49 | Q_PROPERTY(QString serial READ serial) | ||
742 | 50 | QString serial() const; | ||
743 | 51 | |||
744 | 52 | Q_PROPERTY(int index READ index CONSTANT) | ||
745 | 53 | int index() const; | ||
746 | 54 | |||
747 | 55 | Q_PROPERTY(connectivityqt::Sim* sim READ sim NOTIFY simChanged) | ||
748 | 56 | Sim* sim() const; | ||
749 | 57 | |||
750 | 58 | public Q_SLOTS: | ||
751 | 59 | |||
752 | 60 | Q_SIGNALS: | ||
753 | 61 | void simChanged(Sim *sim); | ||
754 | 62 | |||
755 | 63 | protected: | ||
756 | 64 | class Priv; | ||
757 | 65 | std::shared_ptr<Priv> d; | ||
758 | 66 | }; | ||
759 | 67 | |||
760 | 68 | } | ||
761 | 0 | 69 | ||
762 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp' | |||
763 | --- src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp 1970-01-01 00:00:00 +0000 | |||
764 | +++ src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp 2016-04-26 11:24:03 +0000 | |||
765 | @@ -0,0 +1,172 @@ | |||
766 | 1 | /* | ||
767 | 2 | * Copyright © 2016 Canonical Ltd. | ||
768 | 3 | * | ||
769 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
770 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
771 | 6 | * as published by the Free Software Foundation. | ||
772 | 7 | * | ||
773 | 8 | * This program is distributed in the hope that it will be useful, | ||
774 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
775 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
776 | 11 | * GNU Lesser General Public License for more details. | ||
777 | 12 | * | ||
778 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
779 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
780 | 15 | * | ||
781 | 16 | * Authors: | ||
782 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
783 | 18 | */ | ||
784 | 19 | |||
785 | 20 | #include <connectivityqt/modems-list-model.h> | ||
786 | 21 | #include <connectivityqt/modem.h> | ||
787 | 22 | #include <connectivityqt/path.h> | ||
788 | 23 | |||
789 | 24 | #include <QDebug> | ||
790 | 25 | |||
791 | 26 | using namespace std; | ||
792 | 27 | |||
793 | 28 | namespace connectivityqt | ||
794 | 29 | { | ||
795 | 30 | |||
796 | 31 | class ModemsListModel::Priv: public QObject | ||
797 | 32 | { | ||
798 | 33 | Q_OBJECT | ||
799 | 34 | |||
800 | 35 | public: | ||
801 | 36 | Priv(ModemsListModel& parent, const QDBusConnection &connection) : | ||
802 | 37 | p(parent), | ||
803 | 38 | m_connection(connection) | ||
804 | 39 | { | ||
805 | 40 | } | ||
806 | 41 | |||
807 | 42 | void updateModemDBusPaths(QList<QDBusObjectPath> values) | ||
808 | 43 | { | ||
809 | 44 | auto paths = values.toSet(); | ||
810 | 45 | |||
811 | 46 | QSet<QDBusObjectPath> current; | ||
812 | 47 | for (const auto& m: m_modems) | ||
813 | 48 | { | ||
814 | 49 | current << m->path(); | ||
815 | 50 | } | ||
816 | 51 | |||
817 | 52 | auto toRemove(current); | ||
818 | 53 | toRemove.subtract(paths); | ||
819 | 54 | |||
820 | 55 | auto toAdd(paths); | ||
821 | 56 | toAdd.subtract(current); | ||
822 | 57 | |||
823 | 58 | QMutableListIterator<Modem::SPtr> i(m_modems); | ||
824 | 59 | int idx = 0; | ||
825 | 60 | while (i.hasNext()) | ||
826 | 61 | { | ||
827 | 62 | auto modem(i.next()); | ||
828 | 63 | if (toRemove.contains(modem->path())) | ||
829 | 64 | { | ||
830 | 65 | p.beginRemoveRows(QModelIndex(), idx, idx); | ||
831 | 66 | i.remove(); | ||
832 | 67 | p.endRemoveRows(); | ||
833 | 68 | } | ||
834 | 69 | else | ||
835 | 70 | { | ||
836 | 71 | ++idx; | ||
837 | 72 | } | ||
838 | 73 | } | ||
839 | 74 | |||
840 | 75 | if (!toAdd.isEmpty()) | ||
841 | 76 | { | ||
842 | 77 | p.beginInsertRows(QModelIndex(), m_modems.size(), m_modems.size() + toAdd.size() - 1); | ||
843 | 78 | for (const auto& path: toAdd) | ||
844 | 79 | { | ||
845 | 80 | auto modem = std::make_shared<Modem>(path, m_connection, m_sims, this); | ||
846 | 81 | m_modems << modem; | ||
847 | 82 | connect(modem.get(), &Modem::simChanged, this, &Priv::simChanged); | ||
848 | 83 | } | ||
849 | 84 | p.endInsertRows(); | ||
850 | 85 | } | ||
851 | 86 | } | ||
852 | 87 | |||
853 | 88 | QModelIndex findModem(QObject* o) | ||
854 | 89 | { | ||
855 | 90 | auto modem = qobject_cast<Modem*>(o); | ||
856 | 91 | for (auto i = m_modems.constBegin(); i != m_modems.constEnd(); ++i) | ||
857 | 92 | { | ||
858 | 93 | if (i->get() == modem) | ||
859 | 94 | { | ||
860 | 95 | return p.index(std::distance(m_modems.constBegin(), i)); | ||
861 | 96 | } | ||
862 | 97 | } | ||
863 | 98 | return QModelIndex(); | ||
864 | 99 | } | ||
865 | 100 | |||
866 | 101 | public Q_SLOTS: | ||
867 | 102 | void simChanged(Sim *sim) | ||
868 | 103 | { | ||
869 | 104 | auto idx = findModem(sender()); | ||
870 | 105 | p.dataChanged(idx, idx, {ModemsListModel::Roles::RoleSim}); | ||
871 | 106 | } | ||
872 | 107 | |||
873 | 108 | public: | ||
874 | 109 | ModemsListModel& p; | ||
875 | 110 | SimsListModel *m_sims; | ||
876 | 111 | QList<QDBusObjectPath> m_dbus_paths; | ||
877 | 112 | QList<Modem::SPtr> m_modems; | ||
878 | 113 | |||
879 | 114 | const QDBusConnection &m_connection; | ||
880 | 115 | }; | ||
881 | 116 | |||
882 | 117 | ModemsListModel::ModemsListModel(const QDBusConnection& connection, SimsListModel *sims, QObject *parent) : | ||
883 | 118 | QAbstractListModel(parent), | ||
884 | 119 | d(new Priv(*this, connection)) | ||
885 | 120 | { | ||
886 | 121 | d->m_sims = sims; | ||
887 | 122 | } | ||
888 | 123 | |||
889 | 124 | ModemsListModel::~ModemsListModel() | ||
890 | 125 | { | ||
891 | 126 | } | ||
892 | 127 | |||
893 | 128 | int ModemsListModel::columnCount(const QModelIndex &) const | ||
894 | 129 | { | ||
895 | 130 | return 1; | ||
896 | 131 | } | ||
897 | 132 | |||
898 | 133 | int ModemsListModel::rowCount(const QModelIndex &) const | ||
899 | 134 | { | ||
900 | 135 | return d->m_modems.size(); | ||
901 | 136 | } | ||
902 | 137 | |||
903 | 138 | QVariant ModemsListModel::data(const QModelIndex &index, int role) const | ||
904 | 139 | { | ||
905 | 140 | int row(index.row()); | ||
906 | 141 | if (row < 0 || row >= d->m_modems.size()) | ||
907 | 142 | { | ||
908 | 143 | return QVariant(); | ||
909 | 144 | } | ||
910 | 145 | |||
911 | 146 | auto modem = d->m_modems.value(row); | ||
912 | 147 | |||
913 | 148 | switch (role) | ||
914 | 149 | { | ||
915 | 150 | case Roles::RoleIndex: | ||
916 | 151 | return modem->index(); | ||
917 | 152 | break; | ||
918 | 153 | case Roles::RoleSerial: | ||
919 | 154 | return modem->serial(); | ||
920 | 155 | break; | ||
921 | 156 | case Roles::RoleSim: | ||
922 | 157 | return QVariant::fromValue<Sim*>(modem->sim()); | ||
923 | 158 | break; | ||
924 | 159 | } | ||
925 | 160 | |||
926 | 161 | return QVariant(); | ||
927 | 162 | } | ||
928 | 163 | |||
929 | 164 | void ModemsListModel::updateModemDBusPaths(QList<QDBusObjectPath> values) | ||
930 | 165 | { | ||
931 | 166 | d->updateModemDBusPaths(values); | ||
932 | 167 | } | ||
933 | 168 | |||
934 | 169 | |||
935 | 170 | } | ||
936 | 171 | |||
937 | 172 | #include "modems-list-model.moc" | ||
938 | 0 | 173 | ||
939 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h' | |||
940 | --- src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h 1970-01-01 00:00:00 +0000 | |||
941 | +++ src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h 2016-04-26 11:24:03 +0000 | |||
942 | @@ -0,0 +1,78 @@ | |||
943 | 1 | /* | ||
944 | 2 | * Copyright © 2016 Canonical Ltd. | ||
945 | 3 | * | ||
946 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
947 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
948 | 6 | * as published by the Free Software Foundation. | ||
949 | 7 | * | ||
950 | 8 | * This program is distributed in the hope that it will be useful, | ||
951 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
952 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
953 | 11 | * GNU Lesser General Public License for more details. | ||
954 | 12 | * | ||
955 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
956 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
957 | 15 | * | ||
958 | 16 | * Authors: | ||
959 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
960 | 18 | */ | ||
961 | 19 | |||
962 | 20 | #pragma once | ||
963 | 21 | |||
964 | 22 | #include <QAbstractItemModel> | ||
965 | 23 | #include <QDBusConnection> | ||
966 | 24 | #include <QDBusObjectPath> | ||
967 | 25 | |||
968 | 26 | #include <memory> | ||
969 | 27 | |||
970 | 28 | namespace connectivityqt | ||
971 | 29 | { | ||
972 | 30 | |||
973 | 31 | class SimsListModel; | ||
974 | 32 | |||
975 | 33 | class Q_DECL_EXPORT ModemsListModel : public QAbstractListModel | ||
976 | 34 | { | ||
977 | 35 | Q_OBJECT | ||
978 | 36 | |||
979 | 37 | Q_ENUMS(Roles) | ||
980 | 38 | |||
981 | 39 | public: | ||
982 | 40 | |||
983 | 41 | enum Roles | ||
984 | 42 | { | ||
985 | 43 | RoleIndex = Qt::UserRole + 1, | ||
986 | 44 | RoleSerial, | ||
987 | 45 | RoleSim | ||
988 | 46 | }; | ||
989 | 47 | |||
990 | 48 | ModemsListModel(const QDBusConnection &connection, SimsListModel *sims, QObject *parent); | ||
991 | 49 | |||
992 | 50 | ~ModemsListModel(); | ||
993 | 51 | |||
994 | 52 | int columnCount(const QModelIndex &parent) const override; | ||
995 | 53 | |||
996 | 54 | int rowCount(const QModelIndex &parent) const override; | ||
997 | 55 | |||
998 | 56 | QVariant data(const QModelIndex &index, int role) const override; | ||
999 | 57 | |||
1000 | 58 | QHash<int, QByteArray> roleNames() const override | ||
1001 | 59 | { | ||
1002 | 60 | QHash<int, QByteArray> roles; | ||
1003 | 61 | roles[RoleIndex] = "Index"; | ||
1004 | 62 | roles[RoleSerial] = "Serial"; | ||
1005 | 63 | roles[RoleSim] = "Sim"; | ||
1006 | 64 | return roles; | ||
1007 | 65 | } | ||
1008 | 66 | |||
1009 | 67 | void updateModemDBusPaths(QList<QDBusObjectPath> values); | ||
1010 | 68 | |||
1011 | 69 | public Q_SLOTS: | ||
1012 | 70 | |||
1013 | 71 | Q_SIGNALS: | ||
1014 | 72 | |||
1015 | 73 | protected: | ||
1016 | 74 | class Priv; | ||
1017 | 75 | std::shared_ptr<Priv> d; | ||
1018 | 76 | }; | ||
1019 | 77 | |||
1020 | 78 | } | ||
1021 | 0 | 79 | ||
1022 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/path.cpp' | |||
1023 | --- src/connectivity-api/connectivity-qt/connectivityqt/path.cpp 1970-01-01 00:00:00 +0000 | |||
1024 | +++ src/connectivity-api/connectivity-qt/connectivityqt/path.cpp 2016-04-26 11:24:03 +0000 | |||
1025 | @@ -0,0 +1,103 @@ | |||
1026 | 1 | /* | ||
1027 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1028 | 3 | * | ||
1029 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1030 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1031 | 6 | * as published by the Free Software Foundation. | ||
1032 | 7 | * | ||
1033 | 8 | * This program is distributed in the hope that it will be useful, | ||
1034 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1035 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1036 | 11 | * GNU Lesser General Public License for more details. | ||
1037 | 12 | * | ||
1038 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1039 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1040 | 15 | * | ||
1041 | 16 | * Authors: | ||
1042 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1043 | 18 | */ | ||
1044 | 19 | |||
1045 | 20 | #include <connectivityqt/path.h> | ||
1046 | 21 | #include <QDBusObjectPath> | ||
1047 | 22 | |||
1048 | 23 | #include <QDebug> | ||
1049 | 24 | |||
1050 | 25 | namespace connectivityqt | ||
1051 | 26 | { | ||
1052 | 27 | |||
1053 | 28 | class Path::Priv: public QObject | ||
1054 | 29 | { | ||
1055 | 30 | Q_OBJECT | ||
1056 | 31 | |||
1057 | 32 | public: | ||
1058 | 33 | Priv(Path& parent) : | ||
1059 | 34 | p(parent) | ||
1060 | 35 | { | ||
1061 | 36 | } | ||
1062 | 37 | |||
1063 | 38 | public Q_SLOTS: | ||
1064 | 39 | |||
1065 | 40 | public: | ||
1066 | 41 | Path& p; | ||
1067 | 42 | |||
1068 | 43 | QDBusObjectPath m_path; | ||
1069 | 44 | }; | ||
1070 | 45 | |||
1071 | 46 | Path::Path(QObject* parent) | ||
1072 | 47 | : Path("", parent) | ||
1073 | 48 | {} | ||
1074 | 49 | |||
1075 | 50 | Path::Path(const QString& path, QObject* parent) : | ||
1076 | 51 | QObject(parent), d(new Priv(*this)) | ||
1077 | 52 | { | ||
1078 | 53 | setPath(path); | ||
1079 | 54 | } | ||
1080 | 55 | |||
1081 | 56 | Path::Path(const Path& path, QObject* parent) : | ||
1082 | 57 | QObject(parent), d(new Priv(*this)) | ||
1083 | 58 | { | ||
1084 | 59 | setPath(path.path()); | ||
1085 | 60 | } | ||
1086 | 61 | |||
1087 | 62 | |||
1088 | 63 | Path::~Path() | ||
1089 | 64 | { | ||
1090 | 65 | } | ||
1091 | 66 | |||
1092 | 67 | QString Path::path() const | ||
1093 | 68 | { | ||
1094 | 69 | if (d->m_path == QDBusObjectPath("/")) | ||
1095 | 70 | return ""; | ||
1096 | 71 | return d->m_path.path(); | ||
1097 | 72 | } | ||
1098 | 73 | |||
1099 | 74 | void Path::setPath(const QString &value) | ||
1100 | 75 | { | ||
1101 | 76 | QString tmp = value; | ||
1102 | 77 | if (tmp == "") | ||
1103 | 78 | { | ||
1104 | 79 | tmp = "/"; | ||
1105 | 80 | } | ||
1106 | 81 | if (d->m_path == QDBusObjectPath(tmp)) | ||
1107 | 82 | { | ||
1108 | 83 | return; | ||
1109 | 84 | } | ||
1110 | 85 | d->m_path = QDBusObjectPath(tmp); | ||
1111 | 86 | Q_EMIT pathChanged(value); | ||
1112 | 87 | |||
1113 | 88 | /// @todo emit emptyChanged.. | ||
1114 | 89 | } | ||
1115 | 90 | |||
1116 | 91 | void Path::clear() | ||
1117 | 92 | { | ||
1118 | 93 | setPath(""); | ||
1119 | 94 | } | ||
1120 | 95 | |||
1121 | 96 | bool Path::empty() const | ||
1122 | 97 | { | ||
1123 | 98 | return d->m_path == QDBusObjectPath("/"); | ||
1124 | 99 | } | ||
1125 | 100 | |||
1126 | 101 | } | ||
1127 | 102 | |||
1128 | 103 | #include "path.moc" | ||
1129 | 0 | 104 | ||
1130 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/path.h' | |||
1131 | --- src/connectivity-api/connectivity-qt/connectivityqt/path.h 1970-01-01 00:00:00 +0000 | |||
1132 | +++ src/connectivity-api/connectivity-qt/connectivityqt/path.h 2016-04-26 11:24:03 +0000 | |||
1133 | @@ -0,0 +1,59 @@ | |||
1134 | 1 | /* | ||
1135 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1136 | 3 | * | ||
1137 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1138 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1139 | 6 | * as published by the Free Software Foundation. | ||
1140 | 7 | * | ||
1141 | 8 | * This program is distributed in the hope that it will be useful, | ||
1142 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1143 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1144 | 11 | * GNU Lesser General Public License for more details. | ||
1145 | 12 | * | ||
1146 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1147 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1148 | 15 | * | ||
1149 | 16 | * Authors: | ||
1150 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1151 | 18 | */ | ||
1152 | 19 | |||
1153 | 20 | #pragma once | ||
1154 | 21 | |||
1155 | 22 | #include <QObject> | ||
1156 | 23 | #include <memory> | ||
1157 | 24 | |||
1158 | 25 | namespace connectivityqt | ||
1159 | 26 | { | ||
1160 | 27 | |||
1161 | 28 | class Q_DECL_EXPORT Path : public QObject | ||
1162 | 29 | { | ||
1163 | 30 | Q_OBJECT | ||
1164 | 31 | |||
1165 | 32 | public: | ||
1166 | 33 | Path(QObject* parent = 0); | ||
1167 | 34 | Path(const QString& path, QObject* parent = 0); | ||
1168 | 35 | Path(const Path& path, QObject* parent = 0); | ||
1169 | 36 | ~Path(); | ||
1170 | 37 | |||
1171 | 38 | Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) | ||
1172 | 39 | QString path() const; | ||
1173 | 40 | void setPath(const QString &value); | ||
1174 | 41 | |||
1175 | 42 | Q_PROPERTY(bool empty READ empty NOTIFY emptyChanged) | ||
1176 | 43 | bool empty() const; | ||
1177 | 44 | |||
1178 | 45 | public Q_SLOTS: | ||
1179 | 46 | void clear(); | ||
1180 | 47 | |||
1181 | 48 | Q_SIGNALS: | ||
1182 | 49 | void pathChanged(const QString &value); | ||
1183 | 50 | void emptyChanged(bool value); | ||
1184 | 51 | |||
1185 | 52 | protected: | ||
1186 | 53 | class Priv; | ||
1187 | 54 | std::shared_ptr<Priv> d; | ||
1188 | 55 | }; | ||
1189 | 56 | |||
1190 | 57 | } | ||
1191 | 58 | |||
1192 | 59 | Q_DECLARE_METATYPE(connectivityqt::Path*) | ||
1193 | 0 | 60 | ||
1194 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp' | |||
1195 | --- src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp 1970-01-01 00:00:00 +0000 | |||
1196 | +++ src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp 2016-04-26 11:24:03 +0000 | |||
1197 | @@ -0,0 +1,153 @@ | |||
1198 | 1 | /* | ||
1199 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1200 | 3 | * | ||
1201 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1202 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1203 | 6 | * as published by the Free Software Foundation. | ||
1204 | 7 | * | ||
1205 | 8 | * This program is distributed in the hope that it will be useful, | ||
1206 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1207 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1208 | 11 | * GNU Lesser General Public License for more details. | ||
1209 | 12 | * | ||
1210 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1211 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1212 | 15 | * | ||
1213 | 16 | * Authors: | ||
1214 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1215 | 18 | */ | ||
1216 | 19 | |||
1217 | 20 | #include <connectivityqt/internal/dbus-property-cache.h> | ||
1218 | 21 | #include <connectivityqt/sim.h> | ||
1219 | 22 | #include <dbus-types.h> | ||
1220 | 23 | |||
1221 | 24 | #include <SimInterface.h> | ||
1222 | 25 | |||
1223 | 26 | using namespace std; | ||
1224 | 27 | |||
1225 | 28 | namespace connectivityqt | ||
1226 | 29 | { | ||
1227 | 30 | |||
1228 | 31 | class Sim::Priv: public QObject | ||
1229 | 32 | { | ||
1230 | 33 | Q_OBJECT | ||
1231 | 34 | |||
1232 | 35 | public: | ||
1233 | 36 | Priv(Sim& parent) : | ||
1234 | 37 | p(parent) | ||
1235 | 38 | { | ||
1236 | 39 | } | ||
1237 | 40 | |||
1238 | 41 | public Q_SLOTS: | ||
1239 | 42 | void propertyChanged(const QString& name, const QVariant& value) | ||
1240 | 43 | { | ||
1241 | 44 | if (name == "Locked") | ||
1242 | 45 | { | ||
1243 | 46 | Q_EMIT p.lockedChanged(value.toBool()); | ||
1244 | 47 | } else if (name == "Present") | ||
1245 | 48 | { | ||
1246 | 49 | Q_EMIT p.presentChanged(value.toBool()); | ||
1247 | 50 | } else if (name == "DataRoamingEnabled") | ||
1248 | 51 | { | ||
1249 | 52 | Q_EMIT p.dataRoamingEnabledChanged(value.toBool()); | ||
1250 | 53 | } else { | ||
1251 | 54 | qWarning() << "connectivityqt::Sim::Priv::propertyChanged(): " | ||
1252 | 55 | << "Unexpected property: " << name; | ||
1253 | 56 | } | ||
1254 | 57 | |||
1255 | 58 | } | ||
1256 | 59 | |||
1257 | 60 | public: | ||
1258 | 61 | Sim& p; | ||
1259 | 62 | |||
1260 | 63 | unique_ptr<ComUbuntuConnectivity1SimInterface> m_simInterface; | ||
1261 | 64 | |||
1262 | 65 | internal::DBusPropertyCache::UPtr m_propertyCache; | ||
1263 | 66 | }; | ||
1264 | 67 | |||
1265 | 68 | Sim::Sim(const QDBusObjectPath& path, const QDBusConnection& connection, QObject* parent) : | ||
1266 | 69 | QObject(parent), d(new Priv(*this)) | ||
1267 | 70 | { | ||
1268 | 71 | d->m_simInterface = make_unique< | ||
1269 | 72 | ComUbuntuConnectivity1SimInterface>( | ||
1270 | 73 | DBusTypes::DBUS_NAME, path.path(), connection); | ||
1271 | 74 | |||
1272 | 75 | d->m_propertyCache = | ||
1273 | 76 | make_unique<internal::DBusPropertyCache>( | ||
1274 | 77 | DBusTypes::DBUS_NAME, | ||
1275 | 78 | ComUbuntuConnectivity1SimInterface::staticInterfaceName(), | ||
1276 | 79 | path.path(), connection); | ||
1277 | 80 | |||
1278 | 81 | connect(d->m_propertyCache.get(), | ||
1279 | 82 | &internal::DBusPropertyCache::propertyChanged, d.get(), | ||
1280 | 83 | &Priv::propertyChanged); | ||
1281 | 84 | } | ||
1282 | 85 | |||
1283 | 86 | Sim::~Sim() | ||
1284 | 87 | { | ||
1285 | 88 | } | ||
1286 | 89 | |||
1287 | 90 | QDBusObjectPath Sim::path() const | ||
1288 | 91 | { | ||
1289 | 92 | return QDBusObjectPath(d->m_simInterface->path()); | ||
1290 | 93 | } | ||
1291 | 94 | |||
1292 | 95 | QString Sim::imsi() const | ||
1293 | 96 | { | ||
1294 | 97 | return d->m_propertyCache->get("Imsi").toString(); | ||
1295 | 98 | } | ||
1296 | 99 | |||
1297 | 100 | QString Sim::primaryPhoneNumber() const | ||
1298 | 101 | { | ||
1299 | 102 | return d->m_propertyCache->get("PrimaryPhoneNumber").toString(); | ||
1300 | 103 | } | ||
1301 | 104 | |||
1302 | 105 | QList<QString> Sim::phoneNumbers() const | ||
1303 | 106 | { | ||
1304 | 107 | return d->m_propertyCache->get("PhoneNumbers").toStringList(); | ||
1305 | 108 | } | ||
1306 | 109 | |||
1307 | 110 | bool Sim::locked() const | ||
1308 | 111 | { | ||
1309 | 112 | return d->m_propertyCache->get("Locked").toBool(); | ||
1310 | 113 | } | ||
1311 | 114 | |||
1312 | 115 | bool Sim::present() const | ||
1313 | 116 | { | ||
1314 | 117 | return d->m_propertyCache->get("Present").toBool(); | ||
1315 | 118 | } | ||
1316 | 119 | |||
1317 | 120 | QString Sim::mcc() const | ||
1318 | 121 | { | ||
1319 | 122 | return d->m_propertyCache->get("Mcc").toString(); | ||
1320 | 123 | } | ||
1321 | 124 | |||
1322 | 125 | QString Sim::mnc() const | ||
1323 | 126 | { | ||
1324 | 127 | return d->m_propertyCache->get("Mnc").toString(); | ||
1325 | 128 | } | ||
1326 | 129 | |||
1327 | 130 | QList<QString> Sim::preferredLanguages() const | ||
1328 | 131 | { | ||
1329 | 132 | return d->m_propertyCache->get("PreferredLanguages").toStringList(); | ||
1330 | 133 | } | ||
1331 | 134 | |||
1332 | 135 | bool Sim::dataRoamingEnabled() const | ||
1333 | 136 | { | ||
1334 | 137 | return d->m_propertyCache->get("DataRoamingEnabled").toBool(); | ||
1335 | 138 | } | ||
1336 | 139 | |||
1337 | 140 | void Sim::setDataRoamingEnabled(bool value) | ||
1338 | 141 | { | ||
1339 | 142 | d->m_propertyCache->set("DataRoamingEnabled", QVariant(value)); | ||
1340 | 143 | } | ||
1341 | 144 | |||
1342 | 145 | void Sim::unlock() | ||
1343 | 146 | { | ||
1344 | 147 | d->m_simInterface->Unlock(); | ||
1345 | 148 | } | ||
1346 | 149 | |||
1347 | 150 | } | ||
1348 | 151 | |||
1349 | 152 | #include "sim.moc" | ||
1350 | 153 | |||
1351 | 0 | 154 | ||
1352 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/sim.h' | |||
1353 | --- src/connectivity-api/connectivity-qt/connectivityqt/sim.h 1970-01-01 00:00:00 +0000 | |||
1354 | +++ src/connectivity-api/connectivity-qt/connectivityqt/sim.h 2016-04-26 11:24:03 +0000 | |||
1355 | @@ -0,0 +1,90 @@ | |||
1356 | 1 | /* | ||
1357 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1358 | 3 | * | ||
1359 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1360 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1361 | 6 | * as published by the Free Software Foundation. | ||
1362 | 7 | * | ||
1363 | 8 | * This program is distributed in the hope that it will be useful, | ||
1364 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1365 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1366 | 11 | * GNU Lesser General Public License for more details. | ||
1367 | 12 | * | ||
1368 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1369 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1370 | 15 | * | ||
1371 | 16 | * Authors: | ||
1372 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1373 | 18 | */ | ||
1374 | 19 | |||
1375 | 20 | #pragma once | ||
1376 | 21 | |||
1377 | 22 | #include <QDBusConnection> | ||
1378 | 23 | #include <QDBusObjectPath> | ||
1379 | 24 | #include <QObject> | ||
1380 | 25 | |||
1381 | 26 | #include <unity/util/DefinesPtrs.h> | ||
1382 | 27 | |||
1383 | 28 | namespace connectivityqt | ||
1384 | 29 | { | ||
1385 | 30 | |||
1386 | 31 | class Q_DECL_EXPORT Sim : public QObject | ||
1387 | 32 | { | ||
1388 | 33 | Q_OBJECT | ||
1389 | 34 | |||
1390 | 35 | public: | ||
1391 | 36 | UNITY_DEFINES_PTRS(Sim); | ||
1392 | 37 | |||
1393 | 38 | Sim(const QDBusObjectPath& path, const QDBusConnection& connection, QObject* parent = 0); | ||
1394 | 39 | |||
1395 | 40 | virtual ~Sim(); | ||
1396 | 41 | |||
1397 | 42 | Q_PROPERTY(QDBusObjectPath path READ path) | ||
1398 | 43 | QDBusObjectPath path() const; | ||
1399 | 44 | |||
1400 | 45 | Q_PROPERTY(QString Imsi READ imsi CONSTANT) | ||
1401 | 46 | QString imsi() const; | ||
1402 | 47 | |||
1403 | 48 | Q_PROPERTY(QString PrimaryPhoneNumber READ primaryPhoneNumber CONSTANT) | ||
1404 | 49 | QString primaryPhoneNumber() const; | ||
1405 | 50 | |||
1406 | 51 | Q_PROPERTY(QList<QString> PhoneNumbers READ phoneNumbers CONSTANT) | ||
1407 | 52 | QList<QString> phoneNumbers() const; | ||
1408 | 53 | |||
1409 | 54 | Q_PROPERTY(bool Locked READ locked NOTIFY lockedChanged) | ||
1410 | 55 | bool locked() const; | ||
1411 | 56 | |||
1412 | 57 | Q_PROPERTY(bool Present READ present NOTIFY presentChanged) | ||
1413 | 58 | bool present() const; | ||
1414 | 59 | |||
1415 | 60 | Q_PROPERTY(QString Mcc READ mcc CONSTANT) | ||
1416 | 61 | QString mcc() const; | ||
1417 | 62 | |||
1418 | 63 | Q_PROPERTY(QString Mnc READ mnc CONSTANT) | ||
1419 | 64 | QString mnc() const; | ||
1420 | 65 | |||
1421 | 66 | Q_PROPERTY(QList<QString> PreferredLanguages READ preferredLanguages CONSTANT) | ||
1422 | 67 | QList<QString> preferredLanguages() const; | ||
1423 | 68 | |||
1424 | 69 | Q_PROPERTY(bool DataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled NOTIFY dataRoamingEnabledChanged) | ||
1425 | 70 | bool dataRoamingEnabled() const; | ||
1426 | 71 | void setDataRoamingEnabled(bool value); | ||
1427 | 72 | |||
1428 | 73 | public Q_SLOTS: | ||
1429 | 74 | |||
1430 | 75 | void unlock(); | ||
1431 | 76 | |||
1432 | 77 | Q_SIGNALS: | ||
1433 | 78 | void lockedChanged(bool value); | ||
1434 | 79 | void presentChanged(bool value); | ||
1435 | 80 | void dataRoamingEnabledChanged(bool value); | ||
1436 | 81 | |||
1437 | 82 | |||
1438 | 83 | protected: | ||
1439 | 84 | class Priv; | ||
1440 | 85 | std::shared_ptr<Priv> d; | ||
1441 | 86 | }; | ||
1442 | 87 | |||
1443 | 88 | } | ||
1444 | 89 | |||
1445 | 90 | Q_DECLARE_METATYPE(connectivityqt::Sim*) | ||
1446 | 0 | 91 | ||
1447 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp' | |||
1448 | --- src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp 1970-01-01 00:00:00 +0000 | |||
1449 | +++ src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp 2016-04-26 11:24:03 +0000 | |||
1450 | @@ -0,0 +1,214 @@ | |||
1451 | 1 | /* | ||
1452 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1453 | 3 | * | ||
1454 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1455 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1456 | 6 | * as published by the Free Software Foundation. | ||
1457 | 7 | * | ||
1458 | 8 | * This program is distributed in the hope that it will be useful, | ||
1459 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1460 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1461 | 11 | * GNU Lesser General Public License for more details. | ||
1462 | 12 | * | ||
1463 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1464 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1465 | 15 | * | ||
1466 | 16 | * Authors: | ||
1467 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1468 | 18 | */ | ||
1469 | 19 | |||
1470 | 20 | #include <connectivityqt/sims-list-model.h> | ||
1471 | 21 | #include <connectivityqt/path.h> | ||
1472 | 22 | |||
1473 | 23 | #include <QDebug> | ||
1474 | 24 | |||
1475 | 25 | using namespace std; | ||
1476 | 26 | |||
1477 | 27 | namespace connectivityqt | ||
1478 | 28 | { | ||
1479 | 29 | |||
1480 | 30 | class SimsListModel::Priv: public QObject | ||
1481 | 31 | { | ||
1482 | 32 | Q_OBJECT | ||
1483 | 33 | |||
1484 | 34 | public: | ||
1485 | 35 | Priv(SimsListModel& parent, const QDBusConnection &connection) : | ||
1486 | 36 | p(parent), | ||
1487 | 37 | m_connection(connection) | ||
1488 | 38 | { | ||
1489 | 39 | } | ||
1490 | 40 | |||
1491 | 41 | void updateSimDBusPaths(QList<QDBusObjectPath> values) | ||
1492 | 42 | { | ||
1493 | 43 | auto paths = values.toSet(); | ||
1494 | 44 | |||
1495 | 45 | QSet<QDBusObjectPath> current; | ||
1496 | 46 | for (const auto& m: m_sims) | ||
1497 | 47 | { | ||
1498 | 48 | current << m->path(); | ||
1499 | 49 | } | ||
1500 | 50 | |||
1501 | 51 | auto toRemove(current); | ||
1502 | 52 | toRemove.subtract(paths); | ||
1503 | 53 | |||
1504 | 54 | auto toAdd(paths); | ||
1505 | 55 | toAdd.subtract(current); | ||
1506 | 56 | |||
1507 | 57 | QMutableListIterator<Sim::SPtr> i(m_sims); | ||
1508 | 58 | int idx = 0; | ||
1509 | 59 | while (i.hasNext()) | ||
1510 | 60 | { | ||
1511 | 61 | auto sim(i.next()); | ||
1512 | 62 | if (toRemove.contains(sim->path())) | ||
1513 | 63 | { | ||
1514 | 64 | p.beginRemoveRows(QModelIndex(), idx, idx); | ||
1515 | 65 | i.remove(); | ||
1516 | 66 | p.endRemoveRows(); | ||
1517 | 67 | } | ||
1518 | 68 | else | ||
1519 | 69 | { | ||
1520 | 70 | ++idx; | ||
1521 | 71 | } | ||
1522 | 72 | } | ||
1523 | 73 | |||
1524 | 74 | if (!toAdd.isEmpty()) | ||
1525 | 75 | { | ||
1526 | 76 | p.beginInsertRows(QModelIndex(), m_sims.size(), m_sims.size() + toAdd.size() - 1); | ||
1527 | 77 | for (const auto& path: toAdd) | ||
1528 | 78 | { | ||
1529 | 79 | auto sim = std::make_shared<Sim>(path, m_connection, this); | ||
1530 | 80 | m_sims << sim; | ||
1531 | 81 | connect(sim.get(), &Sim::lockedChanged, this, &Priv::lockedChanged); | ||
1532 | 82 | connect(sim.get(), &Sim::presentChanged, this, &Priv::presentChanged); | ||
1533 | 83 | connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Priv::dataRoamingEnabledChanged); | ||
1534 | 84 | } | ||
1535 | 85 | p.endInsertRows(); | ||
1536 | 86 | } | ||
1537 | 87 | } | ||
1538 | 88 | |||
1539 | 89 | QModelIndex findSim(QObject* o) | ||
1540 | 90 | { | ||
1541 | 91 | auto sim = qobject_cast<Sim*>(o); | ||
1542 | 92 | for (auto i = m_sims.constBegin(); i != m_sims.constEnd(); ++i) | ||
1543 | 93 | { | ||
1544 | 94 | if (i->get() == sim) | ||
1545 | 95 | { | ||
1546 | 96 | return p.index(std::distance(m_sims.constBegin(), i)); | ||
1547 | 97 | } | ||
1548 | 98 | } | ||
1549 | 99 | return QModelIndex(); | ||
1550 | 100 | } | ||
1551 | 101 | |||
1552 | 102 | public Q_SLOTS: | ||
1553 | 103 | void lockedChanged() | ||
1554 | 104 | { | ||
1555 | 105 | auto idx = findSim(sender()); | ||
1556 | 106 | p.dataChanged(idx, idx, {SimsListModel::Roles::RoleLocked}); | ||
1557 | 107 | } | ||
1558 | 108 | |||
1559 | 109 | void presentChanged() | ||
1560 | 110 | { | ||
1561 | 111 | auto idx = findSim(sender()); | ||
1562 | 112 | p.dataChanged(idx, idx, {SimsListModel::Roles::RolePresent}); | ||
1563 | 113 | } | ||
1564 | 114 | void dataRoamingEnabledChanged() | ||
1565 | 115 | { | ||
1566 | 116 | auto idx = findSim(sender()); | ||
1567 | 117 | p.dataChanged(idx, idx, {SimsListModel::Roles::RoleDataRoamingEnabled}); | ||
1568 | 118 | } | ||
1569 | 119 | |||
1570 | 120 | public: | ||
1571 | 121 | SimsListModel& p; | ||
1572 | 122 | QList<QDBusObjectPath> m_dbus_paths; | ||
1573 | 123 | QList<Sim::SPtr> m_sims; | ||
1574 | 124 | |||
1575 | 125 | const QDBusConnection &m_connection; | ||
1576 | 126 | }; | ||
1577 | 127 | |||
1578 | 128 | SimsListModel::SimsListModel(const QDBusConnection& connection, QObject *parent) : | ||
1579 | 129 | QAbstractListModel(parent), | ||
1580 | 130 | d(new Priv(*this, connection)) | ||
1581 | 131 | { | ||
1582 | 132 | } | ||
1583 | 133 | |||
1584 | 134 | SimsListModel::~SimsListModel() | ||
1585 | 135 | { | ||
1586 | 136 | } | ||
1587 | 137 | |||
1588 | 138 | int SimsListModel::columnCount(const QModelIndex &) const | ||
1589 | 139 | { | ||
1590 | 140 | return 1; | ||
1591 | 141 | } | ||
1592 | 142 | |||
1593 | 143 | int SimsListModel::rowCount(const QModelIndex &) const | ||
1594 | 144 | { | ||
1595 | 145 | return d->m_sims.size(); | ||
1596 | 146 | } | ||
1597 | 147 | |||
1598 | 148 | QVariant SimsListModel::data(const QModelIndex &index, int role) const | ||
1599 | 149 | { | ||
1600 | 150 | int row(index.row()); | ||
1601 | 151 | if (row < 0 || row >= d->m_sims.size()) | ||
1602 | 152 | { | ||
1603 | 153 | return QVariant(); | ||
1604 | 154 | } | ||
1605 | 155 | |||
1606 | 156 | auto sim = d->m_sims.value(row); | ||
1607 | 157 | |||
1608 | 158 | switch (role) | ||
1609 | 159 | { | ||
1610 | 160 | case Roles::RoleImsi: | ||
1611 | 161 | return sim->imsi(); | ||
1612 | 162 | break; | ||
1613 | 163 | case Roles::RolePrimaryPhoneNumber: | ||
1614 | 164 | return sim->primaryPhoneNumber(); | ||
1615 | 165 | break; | ||
1616 | 166 | case Roles::RolePhoneNumbers: | ||
1617 | 167 | return QVariant::fromValue<QStringList>(sim->phoneNumbers()); | ||
1618 | 168 | break; | ||
1619 | 169 | case RoleLocked: | ||
1620 | 170 | return sim->locked(); | ||
1621 | 171 | break; | ||
1622 | 172 | case RolePresent: | ||
1623 | 173 | return sim->present(); | ||
1624 | 174 | break; | ||
1625 | 175 | case Roles::RoleMcc: | ||
1626 | 176 | return sim->mcc(); | ||
1627 | 177 | break; | ||
1628 | 178 | case Roles::RoleMnc: | ||
1629 | 179 | return sim->mnc(); | ||
1630 | 180 | case Roles::RolePreferredLanguages: | ||
1631 | 181 | return QVariant::fromValue<QStringList>(sim->preferredLanguages()); | ||
1632 | 182 | break; | ||
1633 | 183 | case Roles::RoleDataRoamingEnabled: | ||
1634 | 184 | return sim->dataRoamingEnabled(); | ||
1635 | 185 | break; | ||
1636 | 186 | case Roles::RoleSimObject: | ||
1637 | 187 | return QVariant::fromValue<Sim*>(sim.get()); | ||
1638 | 188 | break; | ||
1639 | 189 | } | ||
1640 | 190 | |||
1641 | 191 | |||
1642 | 192 | return QVariant(); | ||
1643 | 193 | } | ||
1644 | 194 | |||
1645 | 195 | void SimsListModel::updateSimDBusPaths(QList<QDBusObjectPath> values) | ||
1646 | 196 | { | ||
1647 | 197 | d->updateSimDBusPaths(values); | ||
1648 | 198 | } | ||
1649 | 199 | |||
1650 | 200 | Sim *SimsListModel::getSimByPath(const QDBusObjectPath &path) const | ||
1651 | 201 | { | ||
1652 | 202 | for (auto sim : d->m_sims) | ||
1653 | 203 | { | ||
1654 | 204 | if (sim->path() == path) { | ||
1655 | 205 | return sim.get(); | ||
1656 | 206 | } | ||
1657 | 207 | } | ||
1658 | 208 | return nullptr; | ||
1659 | 209 | } | ||
1660 | 210 | |||
1661 | 211 | |||
1662 | 212 | } | ||
1663 | 213 | |||
1664 | 214 | #include "sims-list-model.moc" | ||
1665 | 0 | 215 | ||
1666 | === added file 'src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h' | |||
1667 | --- src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h 1970-01-01 00:00:00 +0000 | |||
1668 | +++ src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h 2016-04-26 11:24:03 +0000 | |||
1669 | @@ -0,0 +1,93 @@ | |||
1670 | 1 | /* | ||
1671 | 2 | * Copyright © 2016 Canonical Ltd. | ||
1672 | 3 | * | ||
1673 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1674 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
1675 | 6 | * as published by the Free Software Foundation. | ||
1676 | 7 | * | ||
1677 | 8 | * This program is distributed in the hope that it will be useful, | ||
1678 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1679 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1680 | 11 | * GNU Lesser General Public License for more details. | ||
1681 | 12 | * | ||
1682 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1683 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1684 | 15 | * | ||
1685 | 16 | * Authors: | ||
1686 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
1687 | 18 | */ | ||
1688 | 19 | |||
1689 | 20 | #pragma once | ||
1690 | 21 | |||
1691 | 22 | #include <QAbstractItemModel> | ||
1692 | 23 | #include <QDBusConnection> | ||
1693 | 24 | #include <QDBusObjectPath> | ||
1694 | 25 | #include <connectivityqt/sim.h> | ||
1695 | 26 | |||
1696 | 27 | #include <memory> | ||
1697 | 28 | |||
1698 | 29 | namespace connectivityqt | ||
1699 | 30 | { | ||
1700 | 31 | |||
1701 | 32 | class Q_DECL_EXPORT SimsListModel : public QAbstractListModel | ||
1702 | 33 | { | ||
1703 | 34 | Q_OBJECT | ||
1704 | 35 | |||
1705 | 36 | Q_ENUMS(Roles) | ||
1706 | 37 | |||
1707 | 38 | public: | ||
1708 | 39 | |||
1709 | 40 | enum Roles | ||
1710 | 41 | { | ||
1711 | 42 | RoleImsi = Qt::UserRole + 1, | ||
1712 | 43 | RolePrimaryPhoneNumber, | ||
1713 | 44 | RolePhoneNumbers, | ||
1714 | 45 | RoleLocked, | ||
1715 | 46 | RolePresent, | ||
1716 | 47 | RoleMcc, | ||
1717 | 48 | RoleMnc, | ||
1718 | 49 | RolePreferredLanguages, | ||
1719 | 50 | RoleDataRoamingEnabled, | ||
1720 | 51 | RoleSimObject | ||
1721 | 52 | }; | ||
1722 | 53 | |||
1723 | 54 | SimsListModel(const QDBusConnection &connection, QObject *parent); | ||
1724 | 55 | |||
1725 | 56 | ~SimsListModel(); | ||
1726 | 57 | |||
1727 | 58 | int columnCount(const QModelIndex &parent) const override; | ||
1728 | 59 | |||
1729 | 60 | int rowCount(const QModelIndex &parent) const override; | ||
1730 | 61 | |||
1731 | 62 | QVariant data(const QModelIndex &index, int role) const override; | ||
1732 | 63 | |||
1733 | 64 | QHash<int, QByteArray> roleNames() const override | ||
1734 | 65 | { | ||
1735 | 66 | QHash<int, QByteArray> roles; | ||
1736 | 67 | roles[RoleImsi] = "Imsi"; | ||
1737 | 68 | roles[RolePrimaryPhoneNumber] = "PrimaryPhoneNumber"; | ||
1738 | 69 | roles[RolePhoneNumbers] = "PhoneNumbers"; | ||
1739 | 70 | roles[RoleLocked] = "Locked"; | ||
1740 | 71 | roles[RolePresent] = "Present"; | ||
1741 | 72 | roles[RoleMcc] = "Mcc"; | ||
1742 | 73 | roles[RoleMnc] = "Mnc"; | ||
1743 | 74 | roles[RolePreferredLanguages] = "PreferredLanguages"; | ||
1744 | 75 | roles[RoleDataRoamingEnabled] = "DataRoamingEnabled"; | ||
1745 | 76 | roles[RoleSimObject] = "SimObject"; | ||
1746 | 77 | return roles; | ||
1747 | 78 | } | ||
1748 | 79 | |||
1749 | 80 | void updateSimDBusPaths(QList<QDBusObjectPath> values); | ||
1750 | 81 | |||
1751 | 82 | Sim *getSimByPath(const QDBusObjectPath &path) const; | ||
1752 | 83 | |||
1753 | 84 | public Q_SLOTS: | ||
1754 | 85 | |||
1755 | 86 | Q_SIGNALS: | ||
1756 | 87 | |||
1757 | 88 | protected: | ||
1758 | 89 | class Priv; | ||
1759 | 90 | std::shared_ptr<Priv> d; | ||
1760 | 91 | }; | ||
1761 | 92 | |||
1762 | 93 | } | ||
1763 | 0 | 94 | ||
1764 | === modified file 'src/indicator/CMakeLists.txt' | |||
1765 | --- src/indicator/CMakeLists.txt 2016-02-15 09:31:38 +0000 | |||
1766 | +++ src/indicator/CMakeLists.txt 2016-04-26 11:24:03 +0000 | |||
1767 | @@ -32,6 +32,9 @@ | |||
1768 | 32 | nmofono/wifi/grouped-access-point.cpp | 32 | nmofono/wifi/grouped-access-point.cpp |
1769 | 33 | nmofono/wifi/wifi-link-impl.cpp | 33 | nmofono/wifi/wifi-link-impl.cpp |
1770 | 34 | nmofono/wwan/modem.cpp | 34 | nmofono/wwan/modem.cpp |
1771 | 35 | nmofono/wwan/sim.cpp | ||
1772 | 36 | nmofono/wwan/sim-manager.cpp | ||
1773 | 37 | nmofono/wwan/qofono-sim-wrapper.cpp | ||
1774 | 35 | nmofono/vpn/openvpn-connection.cpp | 38 | nmofono/vpn/openvpn-connection.cpp |
1775 | 36 | nmofono/vpn/pptp-connection.cpp | 39 | nmofono/vpn/pptp-connection.cpp |
1776 | 37 | nmofono/vpn/vpn-connection.cpp | 40 | nmofono/vpn/vpn-connection.cpp |
1777 | @@ -53,6 +56,8 @@ | |||
1778 | 53 | connectivity-service/dbus-openvpn-connection.cpp | 56 | connectivity-service/dbus-openvpn-connection.cpp |
1779 | 54 | connectivity-service/dbus-pptp-connection.cpp | 57 | connectivity-service/dbus-pptp-connection.cpp |
1780 | 55 | connectivity-service/dbus-vpn-connection.cpp | 58 | connectivity-service/dbus-vpn-connection.cpp |
1781 | 59 | connectivity-service/dbus-modem.cpp | ||
1782 | 60 | connectivity-service/dbus-sim.cpp | ||
1783 | 56 | 61 | ||
1784 | 57 | menuitems/access-point-item.cpp | 62 | menuitems/access-point-item.cpp |
1785 | 58 | menuitems/switch-item.cpp | 63 | menuitems/switch-item.cpp |
1786 | @@ -73,6 +78,22 @@ | |||
1787 | 73 | 78 | ||
1788 | 74 | qt5_add_dbus_adaptor( | 79 | qt5_add_dbus_adaptor( |
1789 | 75 | NETWORK_SERVICE_SOURCES | 80 | NETWORK_SERVICE_SOURCES |
1790 | 81 | "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml" | ||
1791 | 82 | connectivity-service/dbus-modem.h | ||
1792 | 83 | connectivity_service::DBusModem | ||
1793 | 84 | ModemAdaptor | ||
1794 | 85 | ) | ||
1795 | 86 | |||
1796 | 87 | qt5_add_dbus_adaptor( | ||
1797 | 88 | NETWORK_SERVICE_SOURCES | ||
1798 | 89 | "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml" | ||
1799 | 90 | connectivity-service/dbus-sim.h | ||
1800 | 91 | connectivity_service::DBusSim | ||
1801 | 92 | SimAdaptor | ||
1802 | 93 | ) | ||
1803 | 94 | |||
1804 | 95 | qt5_add_dbus_adaptor( | ||
1805 | 96 | NETWORK_SERVICE_SOURCES | ||
1806 | 76 | "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml" | 97 | "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml" |
1807 | 77 | connectivity-service/connectivity-service.h | 98 | connectivity-service/connectivity-service.h |
1808 | 78 | connectivity_service::PrivateService | 99 | connectivity_service::PrivateService |
1809 | 79 | 100 | ||
1810 | === modified file 'src/indicator/connectivity-service/connectivity-service.cpp' | |||
1811 | --- src/indicator/connectivity-service/connectivity-service.cpp 2016-01-14 11:40:59 +0000 | |||
1812 | +++ src/indicator/connectivity-service/connectivity-service.cpp 2016-04-26 11:24:03 +0000 | |||
1813 | @@ -19,6 +19,8 @@ | |||
1814 | 19 | */ | 19 | */ |
1815 | 20 | 20 | ||
1816 | 21 | #include <connectivity-service/connectivity-service.h> | 21 | #include <connectivity-service/connectivity-service.h> |
1817 | 22 | #include <connectivity-service/dbus-modem.h> | ||
1818 | 23 | #include <connectivity-service/dbus-sim.h> | ||
1819 | 22 | #include <connectivity-service/dbus-vpn-connection.h> | 24 | #include <connectivity-service/dbus-vpn-connection.h> |
1820 | 23 | #include <connectivity-service/dbus-openvpn-connection.h> | 25 | #include <connectivity-service/dbus-openvpn-connection.h> |
1821 | 24 | #include <connectivity-service/dbus-pptp-connection.h> | 26 | #include <connectivity-service/dbus-pptp-connection.h> |
1822 | @@ -48,6 +50,9 @@ | |||
1823 | 48 | 50 | ||
1824 | 49 | QMap<QDBusObjectPath, DBusVpnConnection::SPtr> m_vpnConnections; | 51 | QMap<QDBusObjectPath, DBusVpnConnection::SPtr> m_vpnConnections; |
1825 | 50 | 52 | ||
1826 | 53 | QMap<QString, DBusModem::SPtr> m_modems; | ||
1827 | 54 | QMap<QString, DBusSim::SPtr> m_sims; | ||
1828 | 55 | |||
1829 | 51 | shared_ptr<PrivateService> m_privateService; | 56 | shared_ptr<PrivateService> m_privateService; |
1830 | 52 | 57 | ||
1831 | 53 | QStringList m_limitations; | 58 | QStringList m_limitations; |
1832 | @@ -166,6 +171,111 @@ | |||
1833 | 166 | }); | 171 | }); |
1834 | 167 | } | 172 | } |
1835 | 168 | 173 | ||
1836 | 174 | void mobileDataEnabledUpdated(bool value) | ||
1837 | 175 | { | ||
1838 | 176 | Q_UNUSED(value) | ||
1839 | 177 | notifyPrivateProperties({ | ||
1840 | 178 | "MobileDataEnabled" | ||
1841 | 179 | }); | ||
1842 | 180 | } | ||
1843 | 181 | |||
1844 | 182 | void simForMobileDataUpdated() | ||
1845 | 183 | { | ||
1846 | 184 | notifyPrivateProperties({ | ||
1847 | 185 | "SimForMobileData" | ||
1848 | 186 | }); | ||
1849 | 187 | } | ||
1850 | 188 | |||
1851 | 189 | void updateSims() | ||
1852 | 190 | { | ||
1853 | 191 | qDebug() << "updateSims()"; | ||
1854 | 192 | auto current_imsis = m_sims.keys().toSet(); | ||
1855 | 193 | QMap<QString, nmofono::wwan::Sim::Ptr> sims; | ||
1856 | 194 | for (auto i : m_manager->sims()) | ||
1857 | 195 | { | ||
1858 | 196 | sims[i->imsi()] = i; | ||
1859 | 197 | } | ||
1860 | 198 | auto toAdd(sims.keys().toSet()); | ||
1861 | 199 | toAdd.subtract(current_imsis); | ||
1862 | 200 | |||
1863 | 201 | auto toRemove(current_imsis); | ||
1864 | 202 | toRemove.subtract(sims.keys().toSet()); | ||
1865 | 203 | |||
1866 | 204 | for (auto imsi : toRemove) | ||
1867 | 205 | { | ||
1868 | 206 | qDebug() << "Removing " << imsi; | ||
1869 | 207 | m_sims.remove(imsi); | ||
1870 | 208 | } | ||
1871 | 209 | |||
1872 | 210 | for (auto imsi : toAdd) | ||
1873 | 211 | { | ||
1874 | 212 | qDebug() << "Adding " << imsi; | ||
1875 | 213 | |||
1876 | 214 | DBusSim::SPtr dbussim = make_shared<DBusSim>(sims[imsi], m_connection); | ||
1877 | 215 | m_sims[imsi] = dbussim; | ||
1878 | 216 | } | ||
1879 | 217 | |||
1880 | 218 | notifyPrivateProperties({ | ||
1881 | 219 | "Sims" | ||
1882 | 220 | }); | ||
1883 | 221 | } | ||
1884 | 222 | |||
1885 | 223 | void updateModems() | ||
1886 | 224 | { | ||
1887 | 225 | qDebug() << "updateModems() " << m_manager->modems().length(); | ||
1888 | 226 | auto current_serials = m_modems.keys().toSet(); | ||
1889 | 227 | QMap<QString, nmofono::wwan::Modem::Ptr> modems; | ||
1890 | 228 | for (auto i : m_manager->modems()) | ||
1891 | 229 | { | ||
1892 | 230 | modems[i->serial()] = i; | ||
1893 | 231 | } | ||
1894 | 232 | auto toAdd(modems.keys().toSet()); | ||
1895 | 233 | toAdd.subtract(current_serials); | ||
1896 | 234 | |||
1897 | 235 | auto toRemove(current_serials); | ||
1898 | 236 | toRemove.subtract(modems.keys().toSet()); | ||
1899 | 237 | |||
1900 | 238 | for (auto serial : toRemove) | ||
1901 | 239 | { | ||
1902 | 240 | qDebug() << "Removing " << serial; | ||
1903 | 241 | m_modems.remove(serial); | ||
1904 | 242 | } | ||
1905 | 243 | |||
1906 | 244 | for (auto serial : toAdd) | ||
1907 | 245 | { | ||
1908 | 246 | qDebug() << "Adding " << serial; | ||
1909 | 247 | |||
1910 | 248 | wwan::Modem::Ptr m = modems[serial]; | ||
1911 | 249 | |||
1912 | 250 | DBusModem::SPtr dbusmodem = make_shared<DBusModem>(m, m_connection); | ||
1913 | 251 | m_modems[serial] = dbusmodem; | ||
1914 | 252 | qDebug() << "asdfghjklm,nghff: " << m_modems.size(); | ||
1915 | 253 | updateModemSimPath(dbusmodem, m->sim()); | ||
1916 | 254 | connect(m.get(), &wwan::Modem::simUpdated, this, &Private::modemSimUpdated); | ||
1917 | 255 | } | ||
1918 | 256 | notifyPrivateProperties({ | ||
1919 | 257 | "Modems" | ||
1920 | 258 | }); | ||
1921 | 259 | } | ||
1922 | 260 | |||
1923 | 261 | void modemSimUpdated() | ||
1924 | 262 | { | ||
1925 | 263 | auto modem_raw = qobject_cast<wwan::Modem*>(sender()); | ||
1926 | 264 | updateModemSimPath(m_modems[modem_raw->serial()], modem_raw->sim()); | ||
1927 | 265 | } | ||
1928 | 266 | |||
1929 | 267 | void updateModemSimPath(DBusModem::SPtr modem, wwan::Sim::Ptr sim) | ||
1930 | 268 | { | ||
1931 | 269 | if (!sim) | ||
1932 | 270 | { | ||
1933 | 271 | modem->setSim(QDBusObjectPath("/")); | ||
1934 | 272 | } | ||
1935 | 273 | else | ||
1936 | 274 | { | ||
1937 | 275 | modem->setSim(m_sims[sim->imsi()]->path()); | ||
1938 | 276 | } | ||
1939 | 277 | } | ||
1940 | 278 | |||
1941 | 169 | void updateNetworkingStatus() | 279 | void updateNetworkingStatus() |
1942 | 170 | { | 280 | { |
1943 | 171 | QStringList changed; | 281 | QStringList changed; |
1944 | @@ -293,10 +403,17 @@ | |||
1945 | 293 | connect(d->m_manager.get(), &Manager::hotspotAuthChanged, d.get(), &Private::hotspotAuthUpdated); | 403 | connect(d->m_manager.get(), &Manager::hotspotAuthChanged, d.get(), &Private::hotspotAuthUpdated); |
1946 | 294 | connect(d->m_manager.get(), &Manager::hotspotStoredChanged, d.get(), &Private::hotspotStoredUpdated); | 404 | connect(d->m_manager.get(), &Manager::hotspotStoredChanged, d.get(), &Private::hotspotStoredUpdated); |
1947 | 295 | 405 | ||
1948 | 406 | connect(d->m_manager.get(), &Manager::mobileDataEnabledChanged, d.get(), &Private::mobileDataEnabledUpdated); | ||
1949 | 407 | connect(d->m_manager.get(), &Manager::simsChanged, d.get(), &Private::updateSims); | ||
1950 | 408 | connect(d->m_manager.get(), &Manager::modemsChanged, d.get(), &Private::updateModems); | ||
1951 | 409 | connect(d->m_manager.get(), &Manager::simForMobileDataChanged, d.get(), &Private::simForMobileDataUpdated); | ||
1952 | 410 | |||
1953 | 296 | connect(d->m_manager.get(), &Manager::reportError, d->m_privateService.get(), &PrivateService::ReportError); | 411 | connect(d->m_manager.get(), &Manager::reportError, d->m_privateService.get(), &PrivateService::ReportError); |
1954 | 297 | 412 | ||
1955 | 298 | connect(d->m_vpnManager.get(), &vpn::VpnManager::connectionsChanged, d.get(), &Private::updateVpnList); | 413 | connect(d->m_vpnManager.get(), &vpn::VpnManager::connectionsChanged, d.get(), &Private::updateVpnList); |
1956 | 299 | 414 | ||
1957 | 415 | d->updateSims(); | ||
1958 | 416 | d->updateModems(); | ||
1959 | 300 | d->updateNetworkingStatus(); | 417 | d->updateNetworkingStatus(); |
1960 | 301 | d->updateVpnList(); | 418 | d->updateVpnList(); |
1961 | 302 | 419 | ||
1962 | @@ -508,6 +625,74 @@ | |||
1963 | 508 | return paths; | 625 | return paths; |
1964 | 509 | } | 626 | } |
1965 | 510 | 627 | ||
1966 | 628 | bool PrivateService::mobileDataEnabled() const | ||
1967 | 629 | { | ||
1968 | 630 | return p.d->m_manager->mobileDataEnabled(); | ||
1969 | 631 | } | ||
1970 | 632 | |||
1971 | 633 | void PrivateService::setMobileDataEnabled(bool enabled) | ||
1972 | 634 | { | ||
1973 | 635 | p.d->m_manager->setMobileDataEnabled(enabled); | ||
1974 | 636 | } | ||
1975 | 637 | |||
1976 | 638 | QDBusObjectPath PrivateService::simForMobileData() const | ||
1977 | 639 | { | ||
1978 | 640 | wwan::Sim::Ptr sim = p.d->m_manager->simForMobileData(); | ||
1979 | 641 | if (!sim) | ||
1980 | 642 | { | ||
1981 | 643 | return QDBusObjectPath("/"); | ||
1982 | 644 | } | ||
1983 | 645 | |||
1984 | 646 | Q_ASSERT(p.d->m_sims.contains(sim->imsi())); | ||
1985 | 647 | return p.d->m_sims[sim->imsi()]->path(); | ||
1986 | 648 | } | ||
1987 | 649 | |||
1988 | 650 | void PrivateService::setSimForMobileData(const QDBusObjectPath &path) | ||
1989 | 651 | { | ||
1990 | 652 | if (path.path() == "/") | ||
1991 | 653 | { | ||
1992 | 654 | p.d->m_manager->setSimForMobileData(wwan::Sim::Ptr()); | ||
1993 | 655 | return; | ||
1994 | 656 | } | ||
1995 | 657 | |||
1996 | 658 | bool found = false; | ||
1997 | 659 | for (DBusSim::SPtr dbussim: p.d->m_sims) | ||
1998 | 660 | { | ||
1999 | 661 | if (dbussim->path() == path) | ||
2000 | 662 | { | ||
2001 | 663 | found = true; | ||
2002 | 664 | p.d->m_manager->setSimForMobileData(dbussim->sim()); | ||
2003 | 665 | } | ||
2004 | 666 | } | ||
2005 | 667 | |||
2006 | 668 | if (!found) | ||
2007 | 669 | { | ||
2008 | 670 | sendErrorReply(QDBusError::UnknownObject); | ||
2009 | 671 | } | ||
2010 | 672 | } | ||
2011 | 673 | |||
2012 | 674 | QList<QDBusObjectPath> PrivateService::modems() const | ||
2013 | 675 | { | ||
2014 | 676 | auto list = QList<QDBusObjectPath>(); | ||
2015 | 677 | for (DBusModem::SPtr modem : p.d->m_modems) | ||
2016 | 678 | { | ||
2017 | 679 | list << modem->path(); | ||
2018 | 680 | } | ||
2019 | 681 | qDebug() << "FGHJKLKJHG " << list.length(); | ||
2020 | 682 | return list; | ||
2021 | 683 | } | ||
2022 | 684 | |||
2023 | 685 | QList<QDBusObjectPath> PrivateService::sims() const | ||
2024 | 686 | { | ||
2025 | 687 | QList<QDBusObjectPath> paths; | ||
2026 | 688 | |||
2027 | 689 | for (auto dbussim : p.d->m_sims) | ||
2028 | 690 | { | ||
2029 | 691 | paths.append(dbussim->path()); | ||
2030 | 692 | } | ||
2031 | 693 | return paths; | ||
2032 | 694 | } | ||
2033 | 695 | |||
2034 | 511 | } | 696 | } |
2035 | 512 | 697 | ||
2036 | 513 | #include "connectivity-service.moc" | 698 | #include "connectivity-service.moc" |
2037 | 514 | 699 | ||
2038 | === modified file 'src/indicator/connectivity-service/connectivity-service.h' | |||
2039 | --- src/indicator/connectivity-service/connectivity-service.h 2015-12-04 13:18:04 +0000 | |||
2040 | +++ src/indicator/connectivity-service/connectivity-service.h 2016-04-26 11:24:03 +0000 | |||
2041 | @@ -109,6 +109,18 @@ | |||
2042 | 109 | Q_PROPERTY(QList<QDBusObjectPath> VpnConnections READ vpnConnections) | 109 | Q_PROPERTY(QList<QDBusObjectPath> VpnConnections READ vpnConnections) |
2043 | 110 | QList<QDBusObjectPath> vpnConnections() const; | 110 | QList<QDBusObjectPath> vpnConnections() const; |
2044 | 111 | 111 | ||
2045 | 112 | Q_PROPERTY(bool MobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled) | ||
2046 | 113 | bool mobileDataEnabled() const; | ||
2047 | 114 | |||
2048 | 115 | Q_PROPERTY(QDBusObjectPath SimForMobileData READ simForMobileData WRITE setSimForMobileData) | ||
2049 | 116 | QDBusObjectPath simForMobileData() const; | ||
2050 | 117 | |||
2051 | 118 | Q_PROPERTY(QList<QDBusObjectPath> Modems READ modems) | ||
2052 | 119 | QList<QDBusObjectPath> modems() const; | ||
2053 | 120 | |||
2054 | 121 | Q_PROPERTY(QList<QDBusObjectPath> Sims READ sims) | ||
2055 | 122 | QList<QDBusObjectPath> sims() const; | ||
2056 | 123 | |||
2057 | 112 | protected Q_SLOTS: | 124 | protected Q_SLOTS: |
2058 | 113 | void UnlockAllModems(); | 125 | void UnlockAllModems(); |
2059 | 114 | 126 | ||
2060 | @@ -132,6 +144,11 @@ | |||
2061 | 132 | 144 | ||
2062 | 133 | void RemoveVpnConnection(const QDBusObjectPath &path); | 145 | void RemoveVpnConnection(const QDBusObjectPath &path); |
2063 | 134 | 146 | ||
2064 | 147 | void setMobileDataEnabled(bool enabled); | ||
2065 | 148 | |||
2066 | 149 | void setSimForMobileData(const QDBusObjectPath &path); | ||
2067 | 150 | |||
2068 | 151 | |||
2069 | 135 | Q_SIGNALS: | 152 | Q_SIGNALS: |
2070 | 136 | void ReportError(int reason); | 153 | void ReportError(int reason); |
2071 | 137 | 154 | ||
2072 | 138 | 155 | ||
2073 | === added file 'src/indicator/connectivity-service/dbus-modem.cpp' | |||
2074 | --- src/indicator/connectivity-service/dbus-modem.cpp 1970-01-01 00:00:00 +0000 | |||
2075 | +++ src/indicator/connectivity-service/dbus-modem.cpp 2016-04-26 11:24:03 +0000 | |||
2076 | @@ -0,0 +1,98 @@ | |||
2077 | 1 | /* | ||
2078 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
2079 | 3 | * | ||
2080 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2081 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2082 | 6 | * by the Free Software Foundation. | ||
2083 | 7 | * | ||
2084 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2085 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2086 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2087 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2088 | 12 | * | ||
2089 | 13 | * You should have received a copy of the GNU General Public License along | ||
2090 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2091 | 15 | * | ||
2092 | 16 | * Authors: | ||
2093 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
2094 | 18 | */ | ||
2095 | 19 | |||
2096 | 20 | #include <connectivity-service/dbus-modem.h> | ||
2097 | 21 | #include <ModemAdaptor.h> | ||
2098 | 22 | #include <dbus-types.h> | ||
2099 | 23 | #include <util/dbus-utils.h> | ||
2100 | 24 | |||
2101 | 25 | using namespace std; | ||
2102 | 26 | using namespace nmofono::wwan; | ||
2103 | 27 | |||
2104 | 28 | namespace connectivity_service | ||
2105 | 29 | { | ||
2106 | 30 | |||
2107 | 31 | DBusModem::DBusModem(Modem::Ptr modem, | ||
2108 | 32 | const QDBusConnection& connection) : | ||
2109 | 33 | m_modem(modem), | ||
2110 | 34 | m_connection(connection) | ||
2111 | 35 | { | ||
2112 | 36 | m_path.setPath(DBusTypes::modemPath(m_modem->serial())); | ||
2113 | 37 | |||
2114 | 38 | new ModemAdaptor(this); | ||
2115 | 39 | |||
2116 | 40 | registerDBusObject(); | ||
2117 | 41 | } | ||
2118 | 42 | |||
2119 | 43 | DBusModem::~DBusModem() | ||
2120 | 44 | { | ||
2121 | 45 | } | ||
2122 | 46 | |||
2123 | 47 | void DBusModem::registerDBusObject() | ||
2124 | 48 | { | ||
2125 | 49 | if (!m_connection.registerObject(m_path.path(), this)) | ||
2126 | 50 | { | ||
2127 | 51 | qWarning() << "Unable to register Modem object" << m_path.path(); | ||
2128 | 52 | } | ||
2129 | 53 | } | ||
2130 | 54 | |||
2131 | 55 | void DBusModem::notifyProperties(const QStringList& propertyNames) | ||
2132 | 56 | { | ||
2133 | 57 | DBusUtils::notifyPropertyChanged( | ||
2134 | 58 | m_connection, | ||
2135 | 59 | *this, | ||
2136 | 60 | m_path.path(), | ||
2137 | 61 | ModemAdaptor::staticMetaObject.classInfo(ModemAdaptor::staticMetaObject.indexOfClassInfo("D-Bus Interface")).value(), | ||
2138 | 62 | propertyNames | ||
2139 | 63 | ); | ||
2140 | 64 | } | ||
2141 | 65 | |||
2142 | 66 | QDBusObjectPath DBusModem::sim() const | ||
2143 | 67 | { | ||
2144 | 68 | return m_simpath; | ||
2145 | 69 | } | ||
2146 | 70 | |||
2147 | 71 | void DBusModem::setSim(QDBusObjectPath path) | ||
2148 | 72 | { | ||
2149 | 73 | if (m_simpath == path) | ||
2150 | 74 | { | ||
2151 | 75 | return; | ||
2152 | 76 | } | ||
2153 | 77 | m_simpath = path; | ||
2154 | 78 | notifyProperties({"Sim"}); | ||
2155 | 79 | } | ||
2156 | 80 | |||
2157 | 81 | int DBusModem::index() const | ||
2158 | 82 | { | ||
2159 | 83 | return m_modem->index(); | ||
2160 | 84 | } | ||
2161 | 85 | |||
2162 | 86 | |||
2163 | 87 | QString DBusModem::serial() const | ||
2164 | 88 | { | ||
2165 | 89 | return m_modem->serial(); | ||
2166 | 90 | } | ||
2167 | 91 | |||
2168 | 92 | QDBusObjectPath | ||
2169 | 93 | DBusModem::path() const | ||
2170 | 94 | { | ||
2171 | 95 | return m_path; | ||
2172 | 96 | } | ||
2173 | 97 | |||
2174 | 98 | } | ||
2175 | 0 | 99 | ||
2176 | === added file 'src/indicator/connectivity-service/dbus-modem.h' | |||
2177 | --- src/indicator/connectivity-service/dbus-modem.h 1970-01-01 00:00:00 +0000 | |||
2178 | +++ src/indicator/connectivity-service/dbus-modem.h 2016-04-26 11:24:03 +0000 | |||
2179 | @@ -0,0 +1,83 @@ | |||
2180 | 1 | /* | ||
2181 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
2182 | 3 | * | ||
2183 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2184 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2185 | 6 | * by the Free Software Foundation. | ||
2186 | 7 | * | ||
2187 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2188 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2189 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2190 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2191 | 12 | * | ||
2192 | 13 | * You should have received a copy of the GNU General Public License along | ||
2193 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2194 | 15 | * | ||
2195 | 16 | * Authors: | ||
2196 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
2197 | 18 | */ | ||
2198 | 19 | |||
2199 | 20 | #pragma once | ||
2200 | 21 | |||
2201 | 22 | #include <nmofono/wwan/modem.h> | ||
2202 | 23 | |||
2203 | 24 | #include <QDBusConnection> | ||
2204 | 25 | #include <QDBusContext> | ||
2205 | 26 | #include <QDBusObjectPath> | ||
2206 | 27 | #include <QObject> | ||
2207 | 28 | #include <QString> | ||
2208 | 29 | |||
2209 | 30 | #include <unity/util/DefinesPtrs.h> | ||
2210 | 31 | |||
2211 | 32 | class ModemAdaptor; | ||
2212 | 33 | |||
2213 | 34 | namespace connectivity_service | ||
2214 | 35 | { | ||
2215 | 36 | |||
2216 | 37 | class DBusModem: public QObject, protected QDBusContext | ||
2217 | 38 | { | ||
2218 | 39 | Q_OBJECT | ||
2219 | 40 | Q_DISABLE_COPY(DBusModem) | ||
2220 | 41 | |||
2221 | 42 | friend ModemAdaptor; | ||
2222 | 43 | |||
2223 | 44 | public: | ||
2224 | 45 | UNITY_DEFINES_PTRS(DBusModem); | ||
2225 | 46 | |||
2226 | 47 | DBusModem(nmofono::wwan::Modem::Ptr modem, const QDBusConnection& connection); | ||
2227 | 48 | |||
2228 | 49 | virtual ~DBusModem(); | ||
2229 | 50 | |||
2230 | 51 | Q_PROPERTY(int Index READ index) | ||
2231 | 52 | int index() const; | ||
2232 | 53 | |||
2233 | 54 | Q_PROPERTY(QString Serial READ serial) | ||
2234 | 55 | QString serial() const; | ||
2235 | 56 | |||
2236 | 57 | Q_PROPERTY(QDBusObjectPath Sim READ sim) | ||
2237 | 58 | QDBusObjectPath sim() const; | ||
2238 | 59 | |||
2239 | 60 | void setSim(QDBusObjectPath path); | ||
2240 | 61 | |||
2241 | 62 | QDBusObjectPath path() const; | ||
2242 | 63 | |||
2243 | 64 | Q_SIGNALS: | ||
2244 | 65 | |||
2245 | 66 | protected Q_SLOTS: | ||
2246 | 67 | |||
2247 | 68 | private: | ||
2248 | 69 | void notifyProperties(const QStringList& propertyNames); | ||
2249 | 70 | |||
2250 | 71 | protected: | ||
2251 | 72 | void registerDBusObject(); | ||
2252 | 73 | |||
2253 | 74 | nmofono::wwan::Modem::Ptr m_modem; | ||
2254 | 75 | |||
2255 | 76 | QDBusConnection m_connection; | ||
2256 | 77 | |||
2257 | 78 | QDBusObjectPath m_path; | ||
2258 | 79 | QDBusObjectPath m_simpath; | ||
2259 | 80 | |||
2260 | 81 | }; | ||
2261 | 82 | |||
2262 | 83 | } | ||
2263 | 0 | 84 | ||
2264 | === added file 'src/indicator/connectivity-service/dbus-sim.cpp' | |||
2265 | --- src/indicator/connectivity-service/dbus-sim.cpp 1970-01-01 00:00:00 +0000 | |||
2266 | +++ src/indicator/connectivity-service/dbus-sim.cpp 2016-04-26 11:24:03 +0000 | |||
2267 | @@ -0,0 +1,149 @@ | |||
2268 | 1 | /* | ||
2269 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
2270 | 3 | * | ||
2271 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2272 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2273 | 6 | * by the Free Software Foundation. | ||
2274 | 7 | * | ||
2275 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2276 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2277 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2278 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2279 | 12 | * | ||
2280 | 13 | * You should have received a copy of the GNU General Public License along | ||
2281 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2282 | 15 | * | ||
2283 | 16 | * Authors: | ||
2284 | 17 | * Pete Woods <pete.woods@canonical.com> | ||
2285 | 18 | */ | ||
2286 | 19 | |||
2287 | 20 | #include <connectivity-service/dbus-sim.h> | ||
2288 | 21 | #include <SimAdaptor.h> | ||
2289 | 22 | #include <dbus-types.h> | ||
2290 | 23 | #include <util/dbus-utils.h> | ||
2291 | 24 | |||
2292 | 25 | #include <QDebug> | ||
2293 | 26 | |||
2294 | 27 | using namespace std; | ||
2295 | 28 | using namespace nmofono::wwan; | ||
2296 | 29 | |||
2297 | 30 | namespace connectivity_service | ||
2298 | 31 | { | ||
2299 | 32 | |||
2300 | 33 | DBusSim::DBusSim(Sim::Ptr sim, | ||
2301 | 34 | const QDBusConnection& connection) : | ||
2302 | 35 | m_sim(sim), | ||
2303 | 36 | m_connection(connection) | ||
2304 | 37 | { | ||
2305 | 38 | m_path.setPath(DBusTypes::simPath(m_sim->imsi())); | ||
2306 | 39 | |||
2307 | 40 | new SimAdaptor(this); | ||
2308 | 41 | |||
2309 | 42 | registerDBusObject(); | ||
2310 | 43 | |||
2311 | 44 | connect(sim.get(), &Sim::lockedChanged, this, &DBusSim::lockedChanged); | ||
2312 | 45 | connect(sim.get(), &Sim::presentChanged, this, &DBusSim::presentChanged); | ||
2313 | 46 | connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &DBusSim::dataRoamingEnabledChanged); | ||
2314 | 47 | } | ||
2315 | 48 | |||
2316 | 49 | DBusSim::~DBusSim() | ||
2317 | 50 | { | ||
2318 | 51 | } | ||
2319 | 52 | |||
2320 | 53 | QDBusObjectPath DBusSim::path() const | ||
2321 | 54 | { | ||
2322 | 55 | return m_path; | ||
2323 | 56 | } | ||
2324 | 57 | |||
2325 | 58 | void DBusSim::registerDBusObject() | ||
2326 | 59 | { | ||
2327 | 60 | if (!m_connection.registerObject(m_path.path(), this)) | ||
2328 | 61 | { | ||
2329 | 62 | qWarning() << "Unable to register SIM object" << m_path.path(); | ||
2330 | 63 | } | ||
2331 | 64 | } | ||
2332 | 65 | |||
2333 | 66 | void DBusSim::notifyProperties(const QStringList& propertyNames) | ||
2334 | 67 | { | ||
2335 | 68 | DBusUtils::notifyPropertyChanged( | ||
2336 | 69 | m_connection, | ||
2337 | 70 | *this, | ||
2338 | 71 | m_path.path(), | ||
2339 | 72 | SimAdaptor::staticMetaObject.classInfo(SimAdaptor::staticMetaObject.indexOfClassInfo("D-Bus Interface")).value(), | ||
2340 | 73 | propertyNames | ||
2341 | 74 | ); | ||
2342 | 75 | } | ||
2343 | 76 | |||
2344 | 77 | QString DBusSim::imsi() const | ||
2345 | 78 | { | ||
2346 | 79 | return m_sim->imsi(); | ||
2347 | 80 | } | ||
2348 | 81 | |||
2349 | 82 | QString DBusSim::primaryPhoneNumber() const | ||
2350 | 83 | { | ||
2351 | 84 | return m_sim->primaryPhoneNumber(); | ||
2352 | 85 | } | ||
2353 | 86 | |||
2354 | 87 | bool DBusSim::locked() const | ||
2355 | 88 | { | ||
2356 | 89 | return false; | ||
2357 | 90 | } | ||
2358 | 91 | |||
2359 | 92 | bool DBusSim::present() const | ||
2360 | 93 | { | ||
2361 | 94 | return m_sim->present(); | ||
2362 | 95 | } | ||
2363 | 96 | |||
2364 | 97 | QString DBusSim::mcc() const | ||
2365 | 98 | { | ||
2366 | 99 | return m_sim->mcc(); | ||
2367 | 100 | } | ||
2368 | 101 | |||
2369 | 102 | QString DBusSim::mnc() const | ||
2370 | 103 | { | ||
2371 | 104 | return m_sim->mnc(); | ||
2372 | 105 | } | ||
2373 | 106 | |||
2374 | 107 | QStringList DBusSim::preferredLanguages() const | ||
2375 | 108 | { | ||
2376 | 109 | return m_sim->preferredLanguages(); | ||
2377 | 110 | } | ||
2378 | 111 | |||
2379 | 112 | bool DBusSim::dataRoamingEnabled() const | ||
2380 | 113 | { | ||
2381 | 114 | return m_sim->dataRoamingEnabled(); | ||
2382 | 115 | } | ||
2383 | 116 | |||
2384 | 117 | void DBusSim::setDataRoamingEnabled(bool value) const | ||
2385 | 118 | { | ||
2386 | 119 | m_sim->setDataRoamingEnabled(value); | ||
2387 | 120 | } | ||
2388 | 121 | |||
2389 | 122 | void DBusSim::Unlock() | ||
2390 | 123 | { | ||
2391 | 124 | m_sim->unlock(); | ||
2392 | 125 | } | ||
2393 | 126 | |||
2394 | 127 | void DBusSim::lockedChanged() | ||
2395 | 128 | { | ||
2396 | 129 | notifyProperties({"Locked"}); | ||
2397 | 130 | } | ||
2398 | 131 | |||
2399 | 132 | void DBusSim::presentChanged() | ||
2400 | 133 | { | ||
2401 | 134 | notifyProperties({"Present"}); | ||
2402 | 135 | } | ||
2403 | 136 | |||
2404 | 137 | void DBusSim::dataRoamingEnabledChanged() | ||
2405 | 138 | { | ||
2406 | 139 | qDebug() << "DATAROAMINGENABLEDCHANGED"; | ||
2407 | 140 | notifyProperties({"DataRoamingEnabled"}); | ||
2408 | 141 | } | ||
2409 | 142 | |||
2410 | 143 | nmofono::wwan::Sim::Ptr DBusSim::sim() const | ||
2411 | 144 | { | ||
2412 | 145 | return m_sim; | ||
2413 | 146 | } | ||
2414 | 147 | |||
2415 | 148 | |||
2416 | 149 | } | ||
2417 | 0 | 150 | ||
2418 | === added file 'src/indicator/connectivity-service/dbus-sim.h' | |||
2419 | --- src/indicator/connectivity-service/dbus-sim.h 1970-01-01 00:00:00 +0000 | |||
2420 | +++ src/indicator/connectivity-service/dbus-sim.h 2016-04-26 11:24:03 +0000 | |||
2421 | @@ -0,0 +1,103 @@ | |||
2422 | 1 | /* | ||
2423 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
2424 | 3 | * | ||
2425 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2426 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
2427 | 6 | * by the Free Software Foundation. | ||
2428 | 7 | * | ||
2429 | 8 | * This program is distributed in the hope that it will be useful, but | ||
2430 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2431 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2432 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
2433 | 12 | * | ||
2434 | 13 | * You should have received a copy of the GNU General Public License along | ||
2435 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2436 | 15 | * | ||
2437 | 16 | * Authors: | ||
2438 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
2439 | 18 | */ | ||
2440 | 19 | |||
2441 | 20 | #pragma once | ||
2442 | 21 | |||
2443 | 22 | #include <nmofono/wwan/sim.h> | ||
2444 | 23 | |||
2445 | 24 | #include <QDBusConnection> | ||
2446 | 25 | #include <QDBusContext> | ||
2447 | 26 | #include <QDBusObjectPath> | ||
2448 | 27 | #include <QObject> | ||
2449 | 28 | #include <QString> | ||
2450 | 29 | |||
2451 | 30 | #include <unity/util/DefinesPtrs.h> | ||
2452 | 31 | |||
2453 | 32 | class SimAdaptor; | ||
2454 | 33 | |||
2455 | 34 | namespace connectivity_service | ||
2456 | 35 | { | ||
2457 | 36 | |||
2458 | 37 | class DBusSim: public QObject, protected QDBusContext | ||
2459 | 38 | { | ||
2460 | 39 | Q_OBJECT | ||
2461 | 40 | Q_DISABLE_COPY(DBusSim) | ||
2462 | 41 | |||
2463 | 42 | friend SimAdaptor; | ||
2464 | 43 | |||
2465 | 44 | public: | ||
2466 | 45 | UNITY_DEFINES_PTRS(DBusSim); | ||
2467 | 46 | |||
2468 | 47 | DBusSim(nmofono::wwan::Sim::Ptr sim, const QDBusConnection& connection); | ||
2469 | 48 | |||
2470 | 49 | virtual ~DBusSim(); | ||
2471 | 50 | |||
2472 | 51 | Q_PROPERTY(QString Imsi READ imsi) | ||
2473 | 52 | QString imsi() const; | ||
2474 | 53 | |||
2475 | 54 | Q_PROPERTY(QString PrimaryPhoneNumber READ primaryPhoneNumber) | ||
2476 | 55 | QString primaryPhoneNumber() const; | ||
2477 | 56 | |||
2478 | 57 | Q_PROPERTY(bool Locked READ locked) | ||
2479 | 58 | bool locked() const; | ||
2480 | 59 | |||
2481 | 60 | Q_PROPERTY(bool Present READ present) | ||
2482 | 61 | bool present() const; | ||
2483 | 62 | |||
2484 | 63 | Q_PROPERTY(QString Mcc READ mcc) | ||
2485 | 64 | QString mcc() const; | ||
2486 | 65 | |||
2487 | 66 | Q_PROPERTY(QString Mnc READ mnc) | ||
2488 | 67 | QString mnc() const; | ||
2489 | 68 | |||
2490 | 69 | Q_PROPERTY(QStringList PreferredLanguages READ preferredLanguages) | ||
2491 | 70 | QStringList preferredLanguages() const; | ||
2492 | 71 | |||
2493 | 72 | Q_PROPERTY(bool DataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled) | ||
2494 | 73 | bool dataRoamingEnabled() const; | ||
2495 | 74 | void setDataRoamingEnabled(bool value) const; | ||
2496 | 75 | |||
2497 | 76 | QDBusObjectPath path() const; | ||
2498 | 77 | |||
2499 | 78 | nmofono::wwan::Sim::Ptr sim() const; | ||
2500 | 79 | |||
2501 | 80 | Q_SIGNALS: | ||
2502 | 81 | |||
2503 | 82 | protected Q_SLOTS: | ||
2504 | 83 | |||
2505 | 84 | void Unlock(); | ||
2506 | 85 | |||
2507 | 86 | void lockedChanged(); | ||
2508 | 87 | void presentChanged(); | ||
2509 | 88 | void dataRoamingEnabledChanged(); | ||
2510 | 89 | |||
2511 | 90 | private: | ||
2512 | 91 | void notifyProperties(const QStringList& propertyNames); | ||
2513 | 92 | |||
2514 | 93 | protected: | ||
2515 | 94 | void registerDBusObject(); | ||
2516 | 95 | |||
2517 | 96 | nmofono::wwan::Sim::Ptr m_sim; | ||
2518 | 97 | |||
2519 | 98 | QDBusConnection m_connection; | ||
2520 | 99 | |||
2521 | 100 | QDBusObjectPath m_path; | ||
2522 | 101 | }; | ||
2523 | 102 | |||
2524 | 103 | } | ||
2525 | 0 | 104 | ||
2526 | === modified file 'src/indicator/factory.cpp' | |||
2527 | --- src/indicator/factory.cpp 2016-02-15 09:31:38 +0000 | |||
2528 | +++ src/indicator/factory.cpp 2016-04-26 11:24:03 +0000 | |||
2529 | @@ -155,9 +155,9 @@ | |||
2530 | 155 | return make_unique<QuickAccessSection>(d->singletonNmofono(), flightModeSwitch); | 155 | return make_unique<QuickAccessSection>(d->singletonNmofono(), flightModeSwitch); |
2531 | 156 | } | 156 | } |
2532 | 157 | 157 | ||
2534 | 158 | unique_ptr<WwanSection> Factory::newWwanSection(SwitchItem::Ptr hotspotSwitch) | 158 | unique_ptr<WwanSection> Factory::newWwanSection(SwitchItem::Ptr mobileDataSwitch, SwitchItem::Ptr hotspotSwitch) |
2535 | 159 | { | 159 | { |
2537 | 160 | return make_unique<WwanSection>(d->singletonNmofono(), hotspotSwitch); | 160 | return make_unique<WwanSection>(d->singletonNmofono(), mobileDataSwitch, hotspotSwitch); |
2538 | 161 | } | 161 | } |
2539 | 162 | 162 | ||
2540 | 163 | unique_ptr<VpnSection> Factory::newVpnSection() | 163 | unique_ptr<VpnSection> Factory::newVpnSection() |
2541 | @@ -203,6 +203,16 @@ | |||
2542 | 203 | return flightModeSwitch; | 203 | return flightModeSwitch; |
2543 | 204 | } | 204 | } |
2544 | 205 | 205 | ||
2545 | 206 | SwitchItem::UPtr Factory::newMobileDataSwitch() | ||
2546 | 207 | { | ||
2547 | 208 | auto s = make_unique<SwitchItem>(_("Cellular data"), "mobiledata", "enabled"); | ||
2548 | 209 | auto manager = d->singletonNmofono(); | ||
2549 | 210 | //s->setState(manager->flightMode()); | ||
2550 | 211 | //QObject::connect(manager.get(), &nmofono::Manager::flightModeUpdated, flightModeSwitch.get(), &SwitchItem::setState); | ||
2551 | 212 | //QObject::connect(flightModeSwitch.get(), &SwitchItem::stateUpdated, manager.get(), &nmofono::Manager::setFlightMode); | ||
2552 | 213 | return s; | ||
2553 | 214 | } | ||
2554 | 215 | |||
2555 | 206 | SwitchItem::UPtr Factory::newHotspotSwitch() | 216 | SwitchItem::UPtr Factory::newHotspotSwitch() |
2556 | 207 | { | 217 | { |
2557 | 208 | // TODO Move this into a new class | 218 | // TODO Move this into a new class |
2558 | 209 | 219 | ||
2559 | === modified file 'src/indicator/factory.h' | |||
2560 | --- src/indicator/factory.h 2016-02-15 09:31:38 +0000 | |||
2561 | +++ src/indicator/factory.h 2016-04-26 11:24:03 +0000 | |||
2562 | @@ -56,7 +56,7 @@ | |||
2563 | 56 | 56 | ||
2564 | 57 | virtual std::unique_ptr<QuickAccessSection> newQuickAccessSection(SwitchItem::Ptr flightModeSwitch); | 57 | virtual std::unique_ptr<QuickAccessSection> newQuickAccessSection(SwitchItem::Ptr flightModeSwitch); |
2565 | 58 | 58 | ||
2567 | 59 | virtual std::unique_ptr<WwanSection> newWwanSection(SwitchItem::Ptr hotspotSwitch); | 59 | virtual std::unique_ptr<WwanSection> newWwanSection(SwitchItem::Ptr mobileDataSwitch, SwitchItem::Ptr hotspotSwitch); |
2568 | 60 | 60 | ||
2569 | 61 | virtual std::unique_ptr<WifiSection> newWiFiSection(SwitchItem::Ptr wifiSwitch); | 61 | virtual std::unique_ptr<WifiSection> newWiFiSection(SwitchItem::Ptr wifiSwitch); |
2570 | 62 | 62 | ||
2571 | @@ -68,6 +68,8 @@ | |||
2572 | 68 | 68 | ||
2573 | 69 | virtual SwitchItem::UPtr newWifiSwitch(); | 69 | virtual SwitchItem::UPtr newWifiSwitch(); |
2574 | 70 | 70 | ||
2575 | 71 | virtual SwitchItem::UPtr newMobileDataSwitch(); | ||
2576 | 72 | |||
2577 | 71 | virtual SwitchItem::UPtr newFlightModeSwitch(); | 73 | virtual SwitchItem::UPtr newFlightModeSwitch(); |
2578 | 72 | 74 | ||
2579 | 73 | virtual SwitchItem::UPtr newHotspotSwitch(); | 75 | virtual SwitchItem::UPtr newHotspotSwitch(); |
2580 | 74 | 76 | ||
2581 | === modified file 'src/indicator/menu-builder.cpp' | |||
2582 | --- src/indicator/menu-builder.cpp 2015-10-06 10:14:57 +0000 | |||
2583 | +++ src/indicator/menu-builder.cpp 2016-04-26 11:24:03 +0000 | |||
2584 | @@ -43,6 +43,7 @@ | |||
2585 | 43 | RootState::Ptr m_rootState; | 43 | RootState::Ptr m_rootState; |
2586 | 44 | 44 | ||
2587 | 45 | SwitchItem::Ptr m_flightModeSwitch; | 45 | SwitchItem::Ptr m_flightModeSwitch; |
2588 | 46 | SwitchItem::Ptr m_mobileDataSwitch; | ||
2589 | 46 | SwitchItem::Ptr m_hotspotSwitch; | 47 | SwitchItem::Ptr m_hotspotSwitch; |
2590 | 47 | SwitchItem::Ptr m_wifiSwitch; | 48 | SwitchItem::Ptr m_wifiSwitch; |
2591 | 48 | 49 | ||
2592 | @@ -111,6 +112,7 @@ | |||
2593 | 111 | d->m_ubiquityMenu = factory.newIndicatorMenu(d->m_rootState, "ubiquity"); | 112 | d->m_ubiquityMenu = factory.newIndicatorMenu(d->m_rootState, "ubiquity"); |
2594 | 112 | 113 | ||
2595 | 113 | d->m_flightModeSwitch = factory.newFlightModeSwitch(); | 114 | d->m_flightModeSwitch = factory.newFlightModeSwitch(); |
2596 | 115 | d->m_mobileDataSwitch = factory.newMobileDataSwitch(); | ||
2597 | 114 | d->m_hotspotSwitch = factory.newHotspotSwitch(); | 116 | d->m_hotspotSwitch = factory.newHotspotSwitch(); |
2598 | 115 | d->m_wifiSwitch = factory.newWifiSwitch(); | 117 | d->m_wifiSwitch = factory.newWifiSwitch(); |
2599 | 116 | 118 | ||
2600 | @@ -125,7 +127,7 @@ | |||
2601 | 125 | d.get(), &Priv::updateHotspotSwitch); | 127 | d.get(), &Priv::updateHotspotSwitch); |
2602 | 126 | 128 | ||
2603 | 127 | d->m_quickAccessSection = factory.newQuickAccessSection(d->m_flightModeSwitch); | 129 | d->m_quickAccessSection = factory.newQuickAccessSection(d->m_flightModeSwitch); |
2605 | 128 | d->m_wwanSection = factory.newWwanSection(d->m_hotspotSwitch); | 130 | d->m_wwanSection = factory.newWwanSection(d->m_mobileDataSwitch, d->m_hotspotSwitch); |
2606 | 129 | d->m_wifiSection = factory.newWiFiSection(d->m_wifiSwitch); | 131 | d->m_wifiSection = factory.newWiFiSection(d->m_wifiSwitch); |
2607 | 130 | d->m_vpnSection = factory.newVpnSection(); | 132 | d->m_vpnSection = factory.newVpnSection(); |
2608 | 131 | 133 | ||
2609 | 132 | 134 | ||
2610 | === modified file 'src/indicator/nmofono/manager-impl.cpp' | |||
2611 | --- src/indicator/nmofono/manager-impl.cpp 2016-04-06 09:30:45 +0000 | |||
2612 | +++ src/indicator/nmofono/manager-impl.cpp 2016-04-26 11:24:03 +0000 | |||
2613 | @@ -20,6 +20,7 @@ | |||
2614 | 20 | 20 | ||
2615 | 21 | #include <nmofono/manager-impl.h> | 21 | #include <nmofono/manager-impl.h> |
2616 | 22 | #include <nmofono/wifi/wifi-link-impl.h> | 22 | #include <nmofono/wifi/wifi-link-impl.h> |
2617 | 23 | #include <nmofono/wwan/sim-manager.h> | ||
2618 | 23 | #include <NetworkManagerActiveConnectionInterface.h> | 24 | #include <NetworkManagerActiveConnectionInterface.h> |
2619 | 24 | #include <NetworkManagerDeviceInterface.h> | 25 | #include <NetworkManagerDeviceInterface.h> |
2620 | 25 | #include <NetworkManagerInterface.h> | 26 | #include <NetworkManagerInterface.h> |
2621 | @@ -30,6 +31,7 @@ | |||
2622 | 30 | #include <qofono-qt5/qofonomanager.h> | 31 | #include <qofono-qt5/qofonomanager.h> |
2623 | 31 | #include <qofono-qt5/qofonomodem.h> | 32 | #include <qofono-qt5/qofonomodem.h> |
2624 | 32 | #undef slots | 33 | #undef slots |
2625 | 34 | #include <ofono/dbus.h> | ||
2626 | 33 | 35 | ||
2627 | 34 | #include <notify-cpp/notification-manager.h> | 36 | #include <notify-cpp/notification-manager.h> |
2628 | 35 | #include <notify-cpp/snapdecision/sim-unlock.h> | 37 | #include <notify-cpp/snapdecision/sim-unlock.h> |
2629 | @@ -39,6 +41,7 @@ | |||
2630 | 39 | #include <QMap> | 41 | #include <QMap> |
2631 | 40 | #include <QList> | 42 | #include <QList> |
2632 | 41 | #include <QRegularExpression> | 43 | #include <QRegularExpression> |
2633 | 44 | #include <QSettings> | ||
2634 | 42 | #include <NetworkManager.h> | 45 | #include <NetworkManager.h> |
2635 | 43 | #include <QDebug> | 46 | #include <QDebug> |
2636 | 44 | #include <algorithm> | 47 | #include <algorithm> |
2637 | @@ -76,9 +79,113 @@ | |||
2638 | 76 | 79 | ||
2639 | 77 | HotspotManager::SPtr m_hotspotManager; | 80 | HotspotManager::SPtr m_hotspotManager; |
2640 | 78 | 81 | ||
2641 | 82 | bool m_mobileDataEnabled = false; | ||
2642 | 83 | bool m_mobileDataEnabledPending = false; | ||
2643 | 84 | |||
2644 | 85 | wwan::Sim::Ptr m_simForMobileData; | ||
2645 | 86 | bool m_simForMobileDataPending = false; | ||
2646 | 87 | |||
2647 | 88 | QList<wwan::Modem::Ptr> m_modems; | ||
2648 | 89 | QList<wwan::Sim::Ptr> m_sims; | ||
2649 | 90 | |||
2650 | 91 | wwan::SimManager::Ptr m_simManager; | ||
2651 | 92 | |||
2652 | 93 | QSettings *m_settings; | ||
2653 | 94 | |||
2654 | 79 | Private(Manager& parent) : | 95 | Private(Manager& parent) : |
2655 | 80 | p(parent) | 96 | p(parent) |
2656 | 81 | { | 97 | { |
2657 | 98 | m_simManager = make_shared<wwan::SimManager>(); | ||
2658 | 99 | m_sims = m_simManager->knownSims(); | ||
2659 | 100 | connect(m_simManager.get(), &wwan::SimManager::simAdded, this, &Private::simAdded); | ||
2660 | 101 | |||
2661 | 102 | m_settings = new QSettings(QSettings::IniFormat, | ||
2662 | 103 | QSettings::UserScope, | ||
2663 | 104 | "Ubuntu", | ||
2664 | 105 | "connectivityservice", | ||
2665 | 106 | this); | ||
2666 | 107 | QVariant ret = m_settings->value("MobileDataEnabled"); | ||
2667 | 108 | if (ret.isNull()) | ||
2668 | 109 | { | ||
2669 | 110 | /* This is the first time we are running on a system. | ||
2670 | 111 | * | ||
2671 | 112 | * We need to figure out the status of mobile data from looking | ||
2672 | 113 | * at the individual modems. | ||
2673 | 114 | */ | ||
2674 | 115 | m_mobileDataEnabledPending = true; | ||
2675 | 116 | m_settings->setValue("MobileDataEnabled", true); | ||
2676 | 117 | } | ||
2677 | 118 | else | ||
2678 | 119 | { | ||
2679 | 120 | m_mobileDataEnabled = ret.toBool(); | ||
2680 | 121 | } | ||
2681 | 122 | |||
2682 | 123 | ret = m_settings->value("SimForMobileData"); | ||
2683 | 124 | if (ret.isNull()) | ||
2684 | 125 | { | ||
2685 | 126 | /* This is the first time we are running on a system. | ||
2686 | 127 | * | ||
2687 | 128 | * We need to figure out the SIM used for mobile data | ||
2688 | 129 | * from the individual modems. | ||
2689 | 130 | */ | ||
2690 | 131 | m_simForMobileDataPending = true; | ||
2691 | 132 | m_settings->setValue("SimForMobileData", QString()); | ||
2692 | 133 | } | ||
2693 | 134 | else | ||
2694 | 135 | { | ||
2695 | 136 | QString imsi = ret.toString(); | ||
2696 | 137 | wwan::Sim::Ptr sim; | ||
2697 | 138 | for(auto i = m_sims.begin(); i != m_sims.end(); i++) | ||
2698 | 139 | { | ||
2699 | 140 | if ((*i)->imsi() == imsi) { | ||
2700 | 141 | sim = *i; | ||
2701 | 142 | break; | ||
2702 | 143 | } | ||
2703 | 144 | } | ||
2704 | 145 | m_simForMobileData = sim; | ||
2705 | 146 | } | ||
2706 | 147 | |||
2707 | 148 | } | ||
2708 | 149 | |||
2709 | 150 | void matchModemsAndSims() | ||
2710 | 151 | { | ||
2711 | 152 | for (wwan::Modem::Ptr modem: m_modems) | ||
2712 | 153 | { | ||
2713 | 154 | bool match = false; | ||
2714 | 155 | for(wwan::Sim::Ptr sim : m_sims) | ||
2715 | 156 | { | ||
2716 | 157 | if (sim->ofonoPath() == modem->ofonoPath()) | ||
2717 | 158 | { | ||
2718 | 159 | match = true; | ||
2719 | 160 | modem->setSim(sim); | ||
2720 | 161 | break; | ||
2721 | 162 | } | ||
2722 | 163 | } | ||
2723 | 164 | if (!match) | ||
2724 | 165 | { | ||
2725 | 166 | modem->setSim(wwan::Sim::Ptr()); | ||
2726 | 167 | } | ||
2727 | 168 | } | ||
2728 | 169 | } | ||
2729 | 170 | |||
2730 | 171 | void simAdded(wwan::Sim::Ptr sim) | ||
2731 | 172 | { | ||
2732 | 173 | m_sims.append(sim); | ||
2733 | 174 | matchModemsAndSims(); | ||
2734 | 175 | Q_EMIT p.simsChanged(); | ||
2735 | 176 | } | ||
2736 | 177 | |||
2737 | 178 | void modemReady() | ||
2738 | 179 | { | ||
2739 | 180 | wwan::Modem *modem_raw = qobject_cast<wwan::Modem*>(sender()); | ||
2740 | 181 | if (!modem_raw) | ||
2741 | 182 | { | ||
2742 | 183 | qWarning() << "modem cast failed."; | ||
2743 | 184 | return; | ||
2744 | 185 | } | ||
2745 | 186 | m_modems.append(m_ofonoLinks[modem_raw->name()]); | ||
2746 | 187 | matchModemsAndSims(); | ||
2747 | 188 | Q_EMIT p.modemsChanged(); | ||
2748 | 82 | } | 189 | } |
2749 | 83 | 190 | ||
2750 | 84 | void setUnstoppableOperationHappening(bool happening) | 191 | void setUnstoppableOperationHappening(bool happening) |
2751 | @@ -192,6 +299,8 @@ | |||
2752 | 192 | m_pendingUnlocks.removeOne(modem); | 299 | m_pendingUnlocks.removeOne(modem); |
2753 | 193 | disconnect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); | 300 | disconnect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); |
2754 | 194 | } | 301 | } |
2755 | 302 | m_modems.removeAll(modem); | ||
2756 | 303 | Q_EMIT p.modemsChanged(); | ||
2757 | 195 | } | 304 | } |
2758 | 196 | 305 | ||
2759 | 197 | for (const auto& path : toAdd) | 306 | for (const auto& path : toAdd) |
2760 | @@ -202,6 +311,7 @@ | |||
2761 | 202 | auto modem = make_shared<wwan::Modem>(modemInterface); | 311 | auto modem = make_shared<wwan::Modem>(modemInterface); |
2762 | 203 | m_ofonoLinks[path] = modem; | 312 | m_ofonoLinks[path] = modem; |
2763 | 204 | connect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); | 313 | connect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); |
2764 | 314 | connect(modem.get(), &wwan::Modem::ready, this, &Private::modemReady); | ||
2765 | 205 | } | 315 | } |
2766 | 206 | 316 | ||
2767 | 207 | Q_EMIT p.linksUpdated(); | 317 | Q_EMIT p.linksUpdated(); |
2768 | @@ -209,6 +319,69 @@ | |||
2769 | 209 | 319 | ||
2770 | 210 | updateModemAvailable(); | 320 | updateModemAvailable(); |
2771 | 211 | } | 321 | } |
2772 | 322 | |||
2773 | 323 | void setMobileDataEnabled(bool value) { | ||
2774 | 324 | if (m_mobileDataEnabled == value) | ||
2775 | 325 | { | ||
2776 | 326 | return; | ||
2777 | 327 | } | ||
2778 | 328 | |||
2779 | 329 | m_settings->setValue("MobileDataEnabled", value); | ||
2780 | 330 | m_settings->sync(); | ||
2781 | 331 | |||
2782 | 332 | m_mobileDataEnabled = value; | ||
2783 | 333 | Q_EMIT p.mobileDataEnabledChanged(value); | ||
2784 | 334 | |||
2785 | 335 | if (m_mobileDataEnabled) | ||
2786 | 336 | { | ||
2787 | 337 | for (wwan::Modem::Ptr modem : m_modems) | ||
2788 | 338 | { | ||
2789 | 339 | if (modem->sim() && modem->sim() == m_simForMobileData) | ||
2790 | 340 | { | ||
2791 | 341 | modem->sim()->setMobileDataEnabled(true); | ||
2792 | 342 | } | ||
2793 | 343 | } | ||
2794 | 344 | } | ||
2795 | 345 | else | ||
2796 | 346 | { | ||
2797 | 347 | for (wwan::Modem::Ptr modem : m_modems) | ||
2798 | 348 | { | ||
2799 | 349 | if (modem->sim()) { | ||
2800 | 350 | modem->sim()->setMobileDataEnabled(false); | ||
2801 | 351 | } | ||
2802 | 352 | } | ||
2803 | 353 | } | ||
2804 | 354 | } | ||
2805 | 355 | |||
2806 | 356 | void setSimForMobileData(wwan::Sim::Ptr sim) { | ||
2807 | 357 | if (m_simForMobileData == sim) | ||
2808 | 358 | { | ||
2809 | 359 | return; | ||
2810 | 360 | } | ||
2811 | 361 | |||
2812 | 362 | if (m_simForMobileData) | ||
2813 | 363 | { | ||
2814 | 364 | m_simForMobileData->setMobileDataEnabled(false); | ||
2815 | 365 | } | ||
2816 | 366 | |||
2817 | 367 | if (!sim) | ||
2818 | 368 | { | ||
2819 | 369 | m_settings->setValue("SimForMobileData", ""); | ||
2820 | 370 | } | ||
2821 | 371 | else | ||
2822 | 372 | { | ||
2823 | 373 | m_settings->setValue("SimForMobileData", sim->imsi()); | ||
2824 | 374 | } | ||
2825 | 375 | m_settings->sync(); | ||
2826 | 376 | |||
2827 | 377 | m_simForMobileData = sim; | ||
2828 | 378 | if (m_simForMobileData) | ||
2829 | 379 | { | ||
2830 | 380 | m_simForMobileData->setMobileDataEnabled(true); | ||
2831 | 381 | } | ||
2832 | 382 | |||
2833 | 383 | Q_EMIT p.simForMobileDataChanged(); | ||
2834 | 384 | } | ||
2835 | 212 | }; | 385 | }; |
2836 | 213 | 386 | ||
2837 | 214 | void | 387 | void |
2838 | @@ -652,6 +825,43 @@ | |||
2839 | 652 | d->m_hotspotManager->setAuth(auth); | 825 | d->m_hotspotManager->setAuth(auth); |
2840 | 653 | } | 826 | } |
2841 | 654 | 827 | ||
2842 | 828 | bool | ||
2843 | 829 | ManagerImpl::mobileDataEnabled() const | ||
2844 | 830 | { | ||
2845 | 831 | return d->m_mobileDataEnabled; | ||
2846 | 832 | } | ||
2847 | 833 | |||
2848 | 834 | void | ||
2849 | 835 | ManagerImpl::setMobileDataEnabled(bool value) | ||
2850 | 836 | { | ||
2851 | 837 | d->setMobileDataEnabled(value); | ||
2852 | 838 | } | ||
2853 | 839 | |||
2854 | 840 | wwan::Sim::Ptr | ||
2855 | 841 | ManagerImpl::simForMobileData() const | ||
2856 | 842 | { | ||
2857 | 843 | return d->m_simForMobileData; | ||
2858 | 844 | } | ||
2859 | 845 | |||
2860 | 846 | void | ||
2861 | 847 | ManagerImpl::setSimForMobileData(wwan::Sim::Ptr sim) | ||
2862 | 848 | { | ||
2863 | 849 | d->setSimForMobileData(sim); | ||
2864 | 850 | } | ||
2865 | 851 | |||
2866 | 852 | QList<wwan::Modem::Ptr> | ||
2867 | 853 | ManagerImpl::modems() const | ||
2868 | 854 | { | ||
2869 | 855 | return d->m_modems; | ||
2870 | 856 | } | ||
2871 | 857 | |||
2872 | 858 | QList<wwan::Sim::Ptr> | ||
2873 | 859 | ManagerImpl::sims() const | ||
2874 | 860 | { | ||
2875 | 861 | return d->m_sims; | ||
2876 | 862 | } | ||
2877 | 863 | |||
2878 | 864 | |||
2879 | 655 | } | 865 | } |
2880 | 656 | 866 | ||
2881 | 657 | #include "manager-impl.moc" | 867 | #include "manager-impl.moc" |
2882 | 658 | 868 | ||
2883 | === modified file 'src/indicator/nmofono/manager-impl.h' | |||
2884 | --- src/indicator/nmofono/manager-impl.h 2015-10-06 10:19:30 +0000 | |||
2885 | +++ src/indicator/nmofono/manager-impl.h 2016-04-26 11:24:03 +0000 | |||
2886 | @@ -91,6 +91,14 @@ | |||
2887 | 91 | 91 | ||
2888 | 92 | QString hotspotAuth() const override; | 92 | QString hotspotAuth() const override; |
2889 | 93 | 93 | ||
2890 | 94 | bool mobileDataEnabled() const override; | ||
2891 | 95 | |||
2892 | 96 | wwan::Sim::Ptr simForMobileData() const override; | ||
2893 | 97 | |||
2894 | 98 | QList<wwan::Modem::Ptr> modems() const override; | ||
2895 | 99 | |||
2896 | 100 | QList<wwan::Sim::Ptr> sims() const override; | ||
2897 | 101 | |||
2898 | 94 | void setHotspotEnabled(bool) override; | 102 | void setHotspotEnabled(bool) override; |
2899 | 95 | 103 | ||
2900 | 96 | void setHotspotSsid(const QByteArray&) override; | 104 | void setHotspotSsid(const QByteArray&) override; |
2901 | @@ -101,6 +109,10 @@ | |||
2902 | 101 | 109 | ||
2903 | 102 | void setHotspotAuth(const QString&) override; | 110 | void setHotspotAuth(const QString&) override; |
2904 | 103 | 111 | ||
2905 | 112 | void setMobileDataEnabled(bool) override; | ||
2906 | 113 | |||
2907 | 114 | void setSimForMobileData(wwan::Sim::Ptr) override; | ||
2908 | 115 | |||
2909 | 104 | private Q_SLOTS: | 116 | private Q_SLOTS: |
2910 | 105 | void device_added(const QDBusObjectPath &path); | 117 | void device_added(const QDBusObjectPath &path); |
2911 | 106 | void device_removed(const QDBusObjectPath &path); | 118 | void device_removed(const QDBusObjectPath &path); |
2912 | 107 | 119 | ||
2913 | === modified file 'src/indicator/nmofono/manager.h' | |||
2914 | --- src/indicator/nmofono/manager.h 2015-09-15 12:35:22 +0000 | |||
2915 | +++ src/indicator/nmofono/manager.h 2016-04-26 11:24:03 +0000 | |||
2916 | @@ -23,6 +23,7 @@ | |||
2917 | 23 | #include <nmofono/link.h> | 23 | #include <nmofono/link.h> |
2918 | 24 | #include <nmofono/wifi/wifi-link.h> | 24 | #include <nmofono/wifi/wifi-link.h> |
2919 | 25 | #include <nmofono/wwan/modem.h> | 25 | #include <nmofono/wwan/modem.h> |
2920 | 26 | #include <nmofono/wwan/sim.h> | ||
2921 | 26 | 27 | ||
2922 | 27 | #include <memory> | 28 | #include <memory> |
2923 | 28 | #include <QSet> | 29 | #include <QSet> |
2924 | @@ -143,6 +144,19 @@ | |||
2925 | 143 | Q_PROPERTY(QString hotspotAuth READ hotspotAuth WRITE setHotspotAuth NOTIFY hotspotAuthChanged) | 144 | Q_PROPERTY(QString hotspotAuth READ hotspotAuth WRITE setHotspotAuth NOTIFY hotspotAuthChanged) |
2926 | 144 | virtual QString hotspotAuth() const = 0; | 145 | virtual QString hotspotAuth() const = 0; |
2927 | 145 | 146 | ||
2928 | 147 | Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged) | ||
2929 | 148 | virtual bool mobileDataEnabled() const = 0; | ||
2930 | 149 | |||
2931 | 150 | Q_PROPERTY(wwan::Sim::Ptr simForMobileData READ simForMobileData WRITE setSimForMobileData NOTIFY simForMobileDataChanged) | ||
2932 | 151 | virtual wwan::Sim::Ptr simForMobileData() const = 0; | ||
2933 | 152 | |||
2934 | 153 | Q_PROPERTY(QList<wwan::Modem::Ptr> modems READ modems NOTIFY modemsChanged) | ||
2935 | 154 | virtual QList<wwan::Modem::Ptr> modems() const = 0; | ||
2936 | 155 | |||
2937 | 156 | Q_PROPERTY(QList<wwan::Sim::Ptr> sims READ sims NOTIFY simsChanged) | ||
2938 | 157 | virtual QList<wwan::Sim::Ptr> sims() const = 0; | ||
2939 | 158 | |||
2940 | 159 | |||
2941 | 146 | Q_SIGNALS: | 160 | Q_SIGNALS: |
2942 | 147 | void flightModeUpdated(bool); | 161 | void flightModeUpdated(bool); |
2943 | 148 | 162 | ||
2944 | @@ -174,6 +188,14 @@ | |||
2945 | 174 | 188 | ||
2946 | 175 | void unstoppableOperationHappeningUpdated(bool); | 189 | void unstoppableOperationHappeningUpdated(bool); |
2947 | 176 | 190 | ||
2948 | 191 | void mobileDataEnabledChanged(bool); | ||
2949 | 192 | |||
2950 | 193 | void simForMobileDataChanged(); | ||
2951 | 194 | |||
2952 | 195 | void modemsChanged(); | ||
2953 | 196 | |||
2954 | 197 | void simsChanged(); | ||
2955 | 198 | |||
2956 | 177 | public Q_SLOTS: | 199 | public Q_SLOTS: |
2957 | 178 | virtual void setWifiEnabled(bool) = 0; | 200 | virtual void setWifiEnabled(bool) = 0; |
2958 | 179 | 201 | ||
2959 | @@ -189,6 +211,10 @@ | |||
2960 | 189 | 211 | ||
2961 | 190 | virtual void setHotspotAuth(const QString&) = 0; | 212 | virtual void setHotspotAuth(const QString&) = 0; |
2962 | 191 | 213 | ||
2963 | 214 | virtual void setMobileDataEnabled(bool) = 0; | ||
2964 | 215 | |||
2965 | 216 | virtual void setSimForMobileData(wwan::Sim::Ptr) = 0; | ||
2966 | 217 | |||
2967 | 192 | protected: | 218 | protected: |
2968 | 193 | /** | 219 | /** |
2969 | 194 | * @brief The default constructor is protected. | 220 | * @brief The default constructor is protected. |
2970 | 195 | 221 | ||
2971 | === modified file 'src/indicator/nmofono/wwan/modem.cpp' | |||
2972 | --- src/indicator/nmofono/wwan/modem.cpp 2015-08-05 15:14:28 +0000 | |||
2973 | +++ src/indicator/nmofono/wwan/modem.cpp 2016-04-26 11:24:03 +0000 | |||
2974 | @@ -96,6 +96,10 @@ | |||
2975 | 96 | bool m_requiredPinSet = false; | 96 | bool m_requiredPinSet = false; |
2976 | 97 | bool m_retriesSet = false; | 97 | bool m_retriesSet = false; |
2977 | 98 | 98 | ||
2978 | 99 | QString m_serial; | ||
2979 | 100 | bool m_serialSet = false; | ||
2980 | 101 | bool m_readyFired = false; | ||
2981 | 102 | |||
2982 | 99 | QString m_operatorName; | 103 | QString m_operatorName; |
2983 | 100 | Modem::ModemStatus m_status; | 104 | Modem::ModemStatus m_status; |
2984 | 101 | int8_t m_strength; | 105 | int8_t m_strength; |
2985 | @@ -108,6 +112,8 @@ | |||
2986 | 108 | 112 | ||
2987 | 109 | QSet<QString> m_interfaces; | 113 | QSet<QString> m_interfaces; |
2988 | 110 | 114 | ||
2989 | 115 | Sim::Ptr m_sim; | ||
2990 | 116 | |||
2991 | 111 | shared_ptr<QOfonoConnectionManager> m_connectionManager; | 117 | shared_ptr<QOfonoConnectionManager> m_connectionManager; |
2992 | 112 | shared_ptr<QOfonoNetworkRegistration> m_networkRegistration; | 118 | shared_ptr<QOfonoNetworkRegistration> m_networkRegistration; |
2993 | 113 | shared_ptr<QOfonoSimManager> m_simManager; | 119 | shared_ptr<QOfonoSimManager> m_simManager; |
2994 | @@ -125,6 +131,9 @@ | |||
2995 | 125 | connect(m_ofonoModem.get(), &QOfonoModem::interfacesChanged, this, &Private::interfacesChanged); | 131 | connect(m_ofonoModem.get(), &QOfonoModem::interfacesChanged, this, &Private::interfacesChanged); |
2996 | 126 | interfacesChanged(m_ofonoModem->interfaces()); | 132 | interfacesChanged(m_ofonoModem->interfaces()); |
2997 | 127 | 133 | ||
2998 | 134 | connect(m_ofonoModem.get(), &QOfonoModem::serialChanged, this, &Private::serialChanged); | ||
2999 | 135 | serialChanged(m_ofonoModem->serial()); | ||
3000 | 136 | |||
3001 | 128 | /// @todo hook up with system-settings to allow changing the identifier. | 137 | /// @todo hook up with system-settings to allow changing the identifier. |
3002 | 129 | /// for now just provide the defaults | 138 | /// for now just provide the defaults |
3003 | 130 | auto path = m_ofonoModem->modemPath(); | 139 | auto path = m_ofonoModem->modemPath(); |
3004 | @@ -154,6 +163,28 @@ | |||
3005 | 154 | m_shouldTriggerUnlock = false; | 163 | m_shouldTriggerUnlock = false; |
3006 | 155 | Q_EMIT p.readyToUnlock(p.name()); | 164 | Q_EMIT p.readyToUnlock(p.name()); |
3007 | 156 | } | 165 | } |
3008 | 166 | |||
3009 | 167 | if (m_serialSet && !m_readyFired) | ||
3010 | 168 | { | ||
3011 | 169 | m_readyFired = true; | ||
3012 | 170 | Q_EMIT p.ready(); | ||
3013 | 171 | } | ||
3014 | 172 | } | ||
3015 | 173 | |||
3016 | 174 | void serialChanged(const QString &value) { | ||
3017 | 175 | if (m_serial == value) | ||
3018 | 176 | { | ||
3019 | 177 | return; | ||
3020 | 178 | } | ||
3021 | 179 | if (m_serialSet) | ||
3022 | 180 | { | ||
3023 | 181 | qWarning() << "Unexpected update on SERIAL: " << m_serial << ", " << value; | ||
3024 | 182 | } | ||
3025 | 183 | |||
3026 | 184 | m_serial = value; | ||
3027 | 185 | m_serialSet = true; | ||
3028 | 186 | |||
3029 | 187 | update(); | ||
3030 | 157 | } | 188 | } |
3031 | 158 | 189 | ||
3032 | 159 | void connectionManagerChanged(shared_ptr<QOfonoConnectionManager> conmgr) | 190 | void connectionManagerChanged(shared_ptr<QOfonoConnectionManager> conmgr) |
3033 | @@ -662,6 +693,12 @@ | |||
3034 | 662 | QString | 693 | QString |
3035 | 663 | Modem::name() const | 694 | Modem::name() const |
3036 | 664 | { | 695 | { |
3037 | 696 | return ofonoPath(); | ||
3038 | 697 | } | ||
3039 | 698 | |||
3040 | 699 | QString | ||
3041 | 700 | Modem::ofonoPath() const | ||
3042 | 701 | { | ||
3043 | 665 | return d->m_ofonoModem->modemPath(); | 702 | return d->m_ofonoModem->modemPath(); |
3044 | 666 | } | 703 | } |
3045 | 667 | 704 | ||
3046 | @@ -725,8 +762,32 @@ | |||
3047 | 725 | { | 762 | { |
3048 | 726 | d->m_shouldTriggerUnlock = true; | 763 | d->m_shouldTriggerUnlock = true; |
3049 | 727 | } | 764 | } |
3052 | 728 | } | 765 | |
3053 | 729 | 766 | Sim::Ptr Modem::sim() const | |
3054 | 767 | { | ||
3055 | 768 | return d->m_sim; | ||
3056 | 769 | } | ||
3057 | 770 | |||
3058 | 771 | void | ||
3059 | 772 | Modem::setSim(Sim::Ptr sim) | ||
3060 | 773 | { | ||
3061 | 774 | if (d->m_sim == sim) | ||
3062 | 775 | { | ||
3063 | 776 | return; | ||
3064 | 777 | } | ||
3065 | 778 | d->m_sim = sim; | ||
3066 | 779 | Q_EMIT simUpdated(); | ||
3067 | 780 | } | ||
3068 | 781 | |||
3069 | 782 | QString | ||
3070 | 783 | Modem::serial() const | ||
3071 | 784 | { | ||
3072 | 785 | return d->m_serial; | ||
3073 | 786 | } | ||
3074 | 787 | |||
3075 | 788 | |||
3076 | 789 | |||
3077 | 790 | } | ||
3078 | 730 | } | 791 | } |
3079 | 731 | 792 | ||
3080 | 732 | #include "modem.moc" | 793 | #include "modem.moc" |
3081 | 733 | 794 | ||
3082 | === modified file 'src/indicator/nmofono/wwan/modem.h' | |||
3083 | --- src/indicator/nmofono/wwan/modem.h 2015-08-05 15:14:28 +0000 | |||
3084 | +++ src/indicator/nmofono/wwan/modem.h 2016-04-26 11:24:03 +0000 | |||
3085 | @@ -21,6 +21,8 @@ | |||
3086 | 21 | 21 | ||
3087 | 22 | #include <nmofono/wwan/wwan-link.h> | 22 | #include <nmofono/wwan/wwan-link.h> |
3088 | 23 | 23 | ||
3089 | 24 | #include <nmofono/wwan/sim.h> | ||
3090 | 25 | |||
3091 | 24 | #include <map> | 26 | #include <map> |
3092 | 25 | #include <memory> | 27 | #include <memory> |
3093 | 26 | 28 | ||
3094 | @@ -127,8 +129,12 @@ | |||
3095 | 127 | const QString &simIdentifier() const; | 129 | const QString &simIdentifier() const; |
3096 | 128 | 130 | ||
3097 | 129 | int index() const; | 131 | int index() const; |
3098 | 132 | Sim::Ptr sim() const; | ||
3099 | 133 | void setSim(Sim::Ptr sim); | ||
3100 | 134 | QString serial() const; | ||
3101 | 130 | 135 | ||
3102 | 131 | QString name() const override; | 136 | QString name() const override; |
3103 | 137 | QString ofonoPath() const; | ||
3104 | 132 | 138 | ||
3105 | 133 | WwanType wwanType() const override; | 139 | WwanType wwanType() const override; |
3106 | 134 | 140 | ||
3107 | @@ -176,6 +182,10 @@ | |||
3108 | 176 | void resetPinFailed(const QString& error); | 182 | void resetPinFailed(const QString& error); |
3109 | 177 | 183 | ||
3110 | 178 | bool readyToUnlock(const QString& name); | 184 | bool readyToUnlock(const QString& name); |
3111 | 185 | |||
3112 | 186 | void simUpdated(); | ||
3113 | 187 | |||
3114 | 188 | void ready(); | ||
3115 | 179 | }; | 189 | }; |
3116 | 180 | 190 | ||
3117 | 181 | } | 191 | } |
3118 | 182 | 192 | ||
3119 | === added file 'src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp' | |||
3120 | --- src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp 1970-01-01 00:00:00 +0000 | |||
3121 | +++ src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp 2016-04-26 11:24:03 +0000 | |||
3122 | @@ -0,0 +1,251 @@ | |||
3123 | 1 | /* | ||
3124 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
3125 | 3 | * | ||
3126 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3127 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3128 | 6 | * by the Free Software Foundation. | ||
3129 | 7 | * | ||
3130 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3131 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3132 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3133 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3134 | 12 | * | ||
3135 | 13 | * You should have received a copy of the GNU General Public License along | ||
3136 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3137 | 15 | * | ||
3138 | 16 | * Authors: | ||
3139 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
3140 | 18 | */ | ||
3141 | 19 | |||
3142 | 20 | #include <nmofono/wwan/qofono-sim-wrapper.h> | ||
3143 | 21 | |||
3144 | 22 | #include <ofono/dbus.h> | ||
3145 | 23 | |||
3146 | 24 | using namespace std; | ||
3147 | 25 | |||
3148 | 26 | namespace nmofono | ||
3149 | 27 | { | ||
3150 | 28 | namespace wwan | ||
3151 | 29 | { | ||
3152 | 30 | namespace | ||
3153 | 31 | { | ||
3154 | 32 | |||
3155 | 33 | } | ||
3156 | 34 | |||
3157 | 35 | class QOfonoSimWrapper::Private : public QObject, public std::enable_shared_from_this<Private> | ||
3158 | 36 | { | ||
3159 | 37 | Q_OBJECT | ||
3160 | 38 | |||
3161 | 39 | public: | ||
3162 | 40 | |||
3163 | 41 | QOfonoSimWrapper& p; | ||
3164 | 42 | shared_ptr<QOfonoSimManager> m_simManager; | ||
3165 | 43 | |||
3166 | 44 | QString m_imsi; | ||
3167 | 45 | QStringList m_phoneNumbers; | ||
3168 | 46 | QString m_mcc; | ||
3169 | 47 | QString m_mnc; | ||
3170 | 48 | QStringList m_preferredLanguages; | ||
3171 | 49 | |||
3172 | 50 | bool m_present = false; | ||
3173 | 51 | |||
3174 | 52 | bool m_imsiSet = false; | ||
3175 | 53 | bool m_phoneNumbersSet = false; | ||
3176 | 54 | bool m_mccSet = false; | ||
3177 | 55 | bool m_mncSet = false; | ||
3178 | 56 | bool m_preferredLanguagesSet = false; | ||
3179 | 57 | |||
3180 | 58 | |||
3181 | 59 | Private(QOfonoSimWrapper& parent, shared_ptr<QOfonoSimManager> simmgr) | ||
3182 | 60 | : p(parent), m_simManager{simmgr} | ||
3183 | 61 | { | ||
3184 | 62 | connect(simmgr.get(), &QOfonoSimManager::presenceChanged, this, &Private::presentChanged); | ||
3185 | 63 | connect(simmgr.get(), &QOfonoSimManager::subscriberIdentityChanged, this, &Private::imsiChanged); | ||
3186 | 64 | connect(simmgr.get(), &QOfonoSimManager::mobileCountryCodeChanged, this, &Private::mccChanged); | ||
3187 | 65 | connect(simmgr.get(), &QOfonoSimManager::mobileNetworkCodeChanged, this, &Private::mncChanged); | ||
3188 | 66 | connect(simmgr.get(), &QOfonoSimManager::subscriberNumbersChanged, this, &Private::phoneNumbersChanged); | ||
3189 | 67 | connect(simmgr.get(), &QOfonoSimManager::preferredLanguagesChanged, this, &Private::preferredLanguagesChanged); | ||
3190 | 68 | } | ||
3191 | 69 | |||
3192 | 70 | public Q_SLOTS: | ||
3193 | 71 | |||
3194 | 72 | void presentChanged(bool value) | ||
3195 | 73 | { | ||
3196 | 74 | if (m_present == value) | ||
3197 | 75 | { | ||
3198 | 76 | return; | ||
3199 | 77 | } | ||
3200 | 78 | m_present = value; | ||
3201 | 79 | if (!m_present) { | ||
3202 | 80 | m_imsiSet = false; | ||
3203 | 81 | m_phoneNumbersSet = false; | ||
3204 | 82 | m_mccSet = false; | ||
3205 | 83 | m_mncSet = false; | ||
3206 | 84 | m_preferredLanguagesSet = false; | ||
3207 | 85 | Q_EMIT p.readyChanged(false); | ||
3208 | 86 | } | ||
3209 | 87 | Q_EMIT p.presentChanged(value); | ||
3210 | 88 | } | ||
3211 | 89 | |||
3212 | 90 | void imsiChanged(const QString &value) | ||
3213 | 91 | { | ||
3214 | 92 | if (value.isEmpty()) | ||
3215 | 93 | { | ||
3216 | 94 | return; | ||
3217 | 95 | } | ||
3218 | 96 | |||
3219 | 97 | if (m_imsiSet) | ||
3220 | 98 | { | ||
3221 | 99 | qWarning() << "Unexpected update on IMSI: " << m_imsi << ", " << value; | ||
3222 | 100 | } | ||
3223 | 101 | |||
3224 | 102 | m_imsi = value; | ||
3225 | 103 | m_imsiSet = true; | ||
3226 | 104 | if (p.ready()) | ||
3227 | 105 | { | ||
3228 | 106 | Q_EMIT p.readyChanged(true); | ||
3229 | 107 | } | ||
3230 | 108 | } | ||
3231 | 109 | |||
3232 | 110 | void mccChanged(const QString &value) | ||
3233 | 111 | { | ||
3234 | 112 | if (value.isEmpty()) | ||
3235 | 113 | { | ||
3236 | 114 | return; | ||
3237 | 115 | } | ||
3238 | 116 | |||
3239 | 117 | if (m_mccSet) | ||
3240 | 118 | { | ||
3241 | 119 | qWarning() << "Unexpected update on MCC: " << m_mcc << ", " << value; | ||
3242 | 120 | } | ||
3243 | 121 | |||
3244 | 122 | |||
3245 | 123 | m_mcc = value; | ||
3246 | 124 | m_mccSet = true; | ||
3247 | 125 | if (p.ready()) | ||
3248 | 126 | { | ||
3249 | 127 | Q_EMIT p.readyChanged(true); | ||
3250 | 128 | } | ||
3251 | 129 | } | ||
3252 | 130 | |||
3253 | 131 | void mncChanged(const QString &value) | ||
3254 | 132 | { | ||
3255 | 133 | if (value.isEmpty()) | ||
3256 | 134 | { | ||
3257 | 135 | return; | ||
3258 | 136 | } | ||
3259 | 137 | |||
3260 | 138 | if (m_mncSet) | ||
3261 | 139 | { | ||
3262 | 140 | qWarning() << "Unexpected update on MNC: " << m_mnc << ", " << value; | ||
3263 | 141 | } | ||
3264 | 142 | |||
3265 | 143 | m_mnc = value; | ||
3266 | 144 | m_mncSet = true; | ||
3267 | 145 | if (p.ready()) | ||
3268 | 146 | { | ||
3269 | 147 | Q_EMIT p.readyChanged(true); | ||
3270 | 148 | } | ||
3271 | 149 | } | ||
3272 | 150 | |||
3273 | 151 | void phoneNumbersChanged(const QStringList &value) | ||
3274 | 152 | { | ||
3275 | 153 | if (value.isEmpty()) | ||
3276 | 154 | { | ||
3277 | 155 | return; | ||
3278 | 156 | } | ||
3279 | 157 | |||
3280 | 158 | if (m_phoneNumbersSet) | ||
3281 | 159 | { | ||
3282 | 160 | qWarning() << "Unexpected update on Phone Numbers: " << m_phoneNumbers << ", " << value; | ||
3283 | 161 | } | ||
3284 | 162 | |||
3285 | 163 | |||
3286 | 164 | m_phoneNumbers = value; | ||
3287 | 165 | m_phoneNumbersSet = true; | ||
3288 | 166 | if (p.ready()) | ||
3289 | 167 | { | ||
3290 | 168 | Q_EMIT p.readyChanged(true); | ||
3291 | 169 | } | ||
3292 | 170 | } | ||
3293 | 171 | |||
3294 | 172 | void preferredLanguagesChanged(const QStringList &value) | ||
3295 | 173 | { | ||
3296 | 174 | if (value.isEmpty()) | ||
3297 | 175 | { | ||
3298 | 176 | return; | ||
3299 | 177 | } | ||
3300 | 178 | |||
3301 | 179 | if (m_preferredLanguagesSet) | ||
3302 | 180 | { | ||
3303 | 181 | qWarning() << "Unexpected update on Preferred Languages: " << m_preferredLanguages << ", " << value; | ||
3304 | 182 | } | ||
3305 | 183 | |||
3306 | 184 | |||
3307 | 185 | m_preferredLanguages = value; | ||
3308 | 186 | m_preferredLanguagesSet = true; | ||
3309 | 187 | if (p.ready()) | ||
3310 | 188 | { | ||
3311 | 189 | Q_EMIT p.readyChanged(true); | ||
3312 | 190 | } | ||
3313 | 191 | } | ||
3314 | 192 | }; | ||
3315 | 193 | |||
3316 | 194 | |||
3317 | 195 | |||
3318 | 196 | QOfonoSimWrapper::QOfonoSimWrapper(std::shared_ptr<QOfonoSimManager> simmgr) | ||
3319 | 197 | : d{new Private(*this, simmgr)} | ||
3320 | 198 | { | ||
3321 | 199 | } | ||
3322 | 200 | |||
3323 | 201 | QOfonoSimWrapper::~QOfonoSimWrapper() | ||
3324 | 202 | {} | ||
3325 | 203 | |||
3326 | 204 | QString QOfonoSimWrapper::imsi() const | ||
3327 | 205 | { | ||
3328 | 206 | return d->m_imsi; | ||
3329 | 207 | } | ||
3330 | 208 | |||
3331 | 209 | bool QOfonoSimWrapper::present() const | ||
3332 | 210 | { | ||
3333 | 211 | return d->m_present; | ||
3334 | 212 | } | ||
3335 | 213 | |||
3336 | 214 | QString QOfonoSimWrapper::mcc() const | ||
3337 | 215 | { | ||
3338 | 216 | return d->m_mcc; | ||
3339 | 217 | } | ||
3340 | 218 | |||
3341 | 219 | QString QOfonoSimWrapper::mnc() const | ||
3342 | 220 | { | ||
3343 | 221 | return d->m_mnc; | ||
3344 | 222 | } | ||
3345 | 223 | |||
3346 | 224 | QStringList QOfonoSimWrapper::phoneNumbers() const | ||
3347 | 225 | { | ||
3348 | 226 | return d->m_phoneNumbers; | ||
3349 | 227 | } | ||
3350 | 228 | |||
3351 | 229 | QStringList QOfonoSimWrapper::preferredLanguages() const | ||
3352 | 230 | { | ||
3353 | 231 | return d->m_preferredLanguages; | ||
3354 | 232 | } | ||
3355 | 233 | |||
3356 | 234 | bool QOfonoSimWrapper::ready() const { | ||
3357 | 235 | return d->m_imsiSet && | ||
3358 | 236 | d->m_phoneNumbersSet && | ||
3359 | 237 | d->m_mccSet && | ||
3360 | 238 | d->m_mncSet && | ||
3361 | 239 | d->m_preferredLanguagesSet; | ||
3362 | 240 | } | ||
3363 | 241 | |||
3364 | 242 | std::shared_ptr<QOfonoSimManager> QOfonoSimWrapper::ofonoSimManager() const | ||
3365 | 243 | { | ||
3366 | 244 | return d->m_simManager; | ||
3367 | 245 | } | ||
3368 | 246 | |||
3369 | 247 | |||
3370 | 248 | } | ||
3371 | 249 | } | ||
3372 | 250 | |||
3373 | 251 | #include "qofono-sim-wrapper.moc" | ||
3374 | 0 | 252 | ||
3375 | === added file 'src/indicator/nmofono/wwan/qofono-sim-wrapper.h' | |||
3376 | --- src/indicator/nmofono/wwan/qofono-sim-wrapper.h 1970-01-01 00:00:00 +0000 | |||
3377 | +++ src/indicator/nmofono/wwan/qofono-sim-wrapper.h 2016-04-26 11:24:03 +0000 | |||
3378 | @@ -0,0 +1,77 @@ | |||
3379 | 1 | /* | ||
3380 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
3381 | 3 | * | ||
3382 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3383 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3384 | 6 | * by the Free Software Foundation. | ||
3385 | 7 | * | ||
3386 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3387 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3388 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3389 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3390 | 12 | * | ||
3391 | 13 | * You should have received a copy of the GNU General Public License along | ||
3392 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3393 | 15 | * | ||
3394 | 16 | * Authors: | ||
3395 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
3396 | 18 | */ | ||
3397 | 19 | |||
3398 | 20 | #pragma once | ||
3399 | 21 | |||
3400 | 22 | #include <QObject> | ||
3401 | 23 | #include <QSettings> | ||
3402 | 24 | |||
3403 | 25 | #include <memory> | ||
3404 | 26 | |||
3405 | 27 | #define slots | ||
3406 | 28 | #include <qofono-qt5/qofonomodem.h> | ||
3407 | 29 | #include <qofono-qt5/qofonosimmanager.h> | ||
3408 | 30 | #undef slots | ||
3409 | 31 | |||
3410 | 32 | class QOfonoModem; | ||
3411 | 33 | |||
3412 | 34 | namespace nmofono | ||
3413 | 35 | { | ||
3414 | 36 | class ManagerImpl; | ||
3415 | 37 | |||
3416 | 38 | namespace wwan | ||
3417 | 39 | { | ||
3418 | 40 | |||
3419 | 41 | class QOfonoSimWrapper : public QObject | ||
3420 | 42 | { | ||
3421 | 43 | Q_OBJECT | ||
3422 | 44 | |||
3423 | 45 | class Private; | ||
3424 | 46 | std::shared_ptr<Private> d; | ||
3425 | 47 | |||
3426 | 48 | public: | ||
3427 | 49 | |||
3428 | 50 | typedef std::shared_ptr<QOfonoSimWrapper> Ptr; | ||
3429 | 51 | typedef std::weak_ptr<QOfonoSimWrapper> WeakPtr; | ||
3430 | 52 | |||
3431 | 53 | QOfonoSimWrapper() = delete; | ||
3432 | 54 | |||
3433 | 55 | |||
3434 | 56 | QOfonoSimWrapper(std::shared_ptr<QOfonoSimManager> simmgr); | ||
3435 | 57 | ~QOfonoSimWrapper(); | ||
3436 | 58 | |||
3437 | 59 | QString imsi() const; | ||
3438 | 60 | bool present() const; | ||
3439 | 61 | QString mcc() const; | ||
3440 | 62 | QString mnc() const; | ||
3441 | 63 | QStringList phoneNumbers() const; | ||
3442 | 64 | QStringList preferredLanguages() const; | ||
3443 | 65 | bool ready() const; | ||
3444 | 66 | |||
3445 | 67 | std::shared_ptr<QOfonoSimManager> ofonoSimManager() const; | ||
3446 | 68 | |||
3447 | 69 | |||
3448 | 70 | Q_SIGNALS: | ||
3449 | 71 | |||
3450 | 72 | void presentChanged(bool value); | ||
3451 | 73 | void readyChanged(bool value); | ||
3452 | 74 | }; | ||
3453 | 75 | |||
3454 | 76 | } | ||
3455 | 77 | } | ||
3456 | 0 | 78 | ||
3457 | === added file 'src/indicator/nmofono/wwan/sim-manager.cpp' | |||
3458 | --- src/indicator/nmofono/wwan/sim-manager.cpp 1970-01-01 00:00:00 +0000 | |||
3459 | +++ src/indicator/nmofono/wwan/sim-manager.cpp 2016-04-26 11:24:03 +0000 | |||
3460 | @@ -0,0 +1,271 @@ | |||
3461 | 1 | /* | ||
3462 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
3463 | 3 | * | ||
3464 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3465 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3466 | 6 | * by the Free Software Foundation. | ||
3467 | 7 | * | ||
3468 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3469 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3470 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3471 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3472 | 12 | * | ||
3473 | 13 | * You should have received a copy of the GNU General Public License along | ||
3474 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3475 | 15 | * | ||
3476 | 16 | * Authors: | ||
3477 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
3478 | 18 | */ | ||
3479 | 19 | |||
3480 | 20 | #include <nmofono/wwan/sim-manager.h> | ||
3481 | 21 | |||
3482 | 22 | #include <nmofono/wwan/qofono-sim-wrapper.h> | ||
3483 | 23 | |||
3484 | 24 | #define slots | ||
3485 | 25 | #include <qofono-qt5/qofonomanager.h> | ||
3486 | 26 | #include <qofono-qt5/qofonomodem.h> | ||
3487 | 27 | #include <qofono-qt5/qofonosimmanager.h> | ||
3488 | 28 | #undef slots | ||
3489 | 29 | #include <ofono/dbus.h> | ||
3490 | 30 | |||
3491 | 31 | using namespace std; | ||
3492 | 32 | |||
3493 | 33 | namespace nmofono | ||
3494 | 34 | { | ||
3495 | 35 | namespace wwan | ||
3496 | 36 | { | ||
3497 | 37 | namespace | ||
3498 | 38 | { | ||
3499 | 39 | |||
3500 | 40 | } | ||
3501 | 41 | |||
3502 | 42 | class SimManager::Private : public QObject, public std::enable_shared_from_this<Private> | ||
3503 | 43 | { | ||
3504 | 44 | Q_OBJECT | ||
3505 | 45 | |||
3506 | 46 | public: | ||
3507 | 47 | |||
3508 | 48 | SimManager& p; | ||
3509 | 49 | |||
3510 | 50 | QMap<QString, Sim::Ptr> m_knownSims; | ||
3511 | 51 | |||
3512 | 52 | shared_ptr<QOfonoManager> m_ofono; | ||
3513 | 53 | QMap<QString, shared_ptr<QOfonoModem>> m_ofonoModems; | ||
3514 | 54 | QMap<QString, QOfonoSimWrapper::Ptr> m_wrappers; | ||
3515 | 55 | |||
3516 | 56 | QSettings *m_settings; | ||
3517 | 57 | |||
3518 | 58 | Private(SimManager& parent) | ||
3519 | 59 | : p(parent) | ||
3520 | 60 | { | ||
3521 | 61 | m_settings = new QSettings(QSettings::IniFormat, | ||
3522 | 62 | QSettings::UserScope, | ||
3523 | 63 | "Ubuntu", | ||
3524 | 64 | "connectivityservice", | ||
3525 | 65 | this); | ||
3526 | 66 | |||
3527 | 67 | QVariant ret; | ||
3528 | 68 | ret = m_settings->value("KnownSims"); | ||
3529 | 69 | if (ret.isNull()) | ||
3530 | 70 | { | ||
3531 | 71 | /* This is the first time we are running on a system. | ||
3532 | 72 | */ | ||
3533 | 73 | m_settings->setValue("KnownSims", QVariant(QVariant::StringList)); | ||
3534 | 74 | } | ||
3535 | 75 | else | ||
3536 | 76 | { | ||
3537 | 77 | QStringList imsis = ret.toStringList(); | ||
3538 | 78 | for(auto imsi : imsis) { | ||
3539 | 79 | auto sim = wwan::Sim::createFromSettings(m_settings, imsi); | ||
3540 | 80 | connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Private::simDataRoamingEnabledChanged); | ||
3541 | 81 | if (!sim) | ||
3542 | 82 | { | ||
3543 | 83 | continue; | ||
3544 | 84 | } | ||
3545 | 85 | m_knownSims[sim->imsi()] = sim; | ||
3546 | 86 | } | ||
3547 | 87 | } | ||
3548 | 88 | |||
3549 | 89 | m_ofono = make_shared<QOfonoManager>(); | ||
3550 | 90 | connect(m_ofono.get(), &QOfonoManager::modemsChanged, this, &Private::modemsChanged); | ||
3551 | 91 | modemsChanged(m_ofono->modems()); | ||
3552 | 92 | } | ||
3553 | 93 | |||
3554 | 94 | public Q_SLOTS: | ||
3555 | 95 | |||
3556 | 96 | void modemsChanged(const QStringList& value) | ||
3557 | 97 | { | ||
3558 | 98 | QSet<QString> modemPaths(value.toSet()); | ||
3559 | 99 | QSet<QString> currentModemPaths(m_ofonoModems.keys().toSet()); | ||
3560 | 100 | |||
3561 | 101 | auto toRemove = currentModemPaths; | ||
3562 | 102 | toRemove.subtract(modemPaths); | ||
3563 | 103 | |||
3564 | 104 | auto toAdd = modemPaths; | ||
3565 | 105 | toAdd.subtract(currentModemPaths); | ||
3566 | 106 | |||
3567 | 107 | for (const auto& path : toRemove) | ||
3568 | 108 | { | ||
3569 | 109 | if (!m_ofonoModems.contains(path)) | ||
3570 | 110 | { | ||
3571 | 111 | qWarning("Something went horribly wrong."); | ||
3572 | 112 | continue; | ||
3573 | 113 | } | ||
3574 | 114 | auto modem = m_ofonoModems.take(path); | ||
3575 | 115 | if (m_wrappers.contains(path)) | ||
3576 | 116 | { | ||
3577 | 117 | auto wrapper = m_wrappers[path]; | ||
3578 | 118 | if (m_knownSims.contains(wrapper->imsi())) | ||
3579 | 119 | { | ||
3580 | 120 | auto sim = m_knownSims[wrapper->imsi()]; | ||
3581 | 121 | sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); | ||
3582 | 122 | } | ||
3583 | 123 | m_wrappers.remove(path); | ||
3584 | 124 | } | ||
3585 | 125 | } | ||
3586 | 126 | |||
3587 | 127 | for (const auto& path : toAdd) | ||
3588 | 128 | { | ||
3589 | 129 | auto modem = make_shared<QOfonoModem>(); | ||
3590 | 130 | modem->setModemPath(path); | ||
3591 | 131 | |||
3592 | 132 | if (m_ofonoModems.contains(path)) | ||
3593 | 133 | { | ||
3594 | 134 | qWarning("Something went horribly wrong."); | ||
3595 | 135 | } | ||
3596 | 136 | m_ofonoModems[path] = modem; | ||
3597 | 137 | |||
3598 | 138 | connect(modem.get(), &QOfonoModem::interfacesChanged, this, &Private::modemInterfacesChanged); | ||
3599 | 139 | // use Q_EMIT to get the sender() set. | ||
3600 | 140 | Q_EMIT modem->interfacesChanged(modem->interfaces()); | ||
3601 | 141 | } | ||
3602 | 142 | } | ||
3603 | 143 | |||
3604 | 144 | void modemInterfacesChanged() { | ||
3605 | 145 | QOfonoModem *modem = qobject_cast<QOfonoModem*>(sender()); | ||
3606 | 146 | if (!modem) | ||
3607 | 147 | { | ||
3608 | 148 | qWarning() << "Unable to cast sender()."; | ||
3609 | 149 | return; | ||
3610 | 150 | } | ||
3611 | 151 | |||
3612 | 152 | QSet<QString> interfaces(modem->interfaces().toSet()); | ||
3613 | 153 | if (interfaces.contains(OFONO_SIM_MANAGER_INTERFACE)) | ||
3614 | 154 | { | ||
3615 | 155 | if (!m_wrappers.contains(modem->modemPath())) | ||
3616 | 156 | { | ||
3617 | 157 | auto simmgr = make_shared<QOfonoSimManager>(); | ||
3618 | 158 | simmgr->setModemPath(modem->modemPath()); | ||
3619 | 159 | |||
3620 | 160 | auto wrapper = make_shared<wwan::QOfonoSimWrapper>(simmgr); | ||
3621 | 161 | |||
3622 | 162 | connect(wrapper.get(), &wwan::QOfonoSimWrapper::presentChanged, this, &Private::ofonoSimPresentChanged); | ||
3623 | 163 | connect(wrapper.get(), &wwan::QOfonoSimWrapper::readyChanged, this, &Private::ofonoSimReady); | ||
3624 | 164 | |||
3625 | 165 | m_wrappers[modem->modemPath()] = wrapper; | ||
3626 | 166 | } | ||
3627 | 167 | |||
3628 | 168 | } else { | ||
3629 | 169 | if (m_wrappers.contains(modem->modemPath())) | ||
3630 | 170 | { | ||
3631 | 171 | auto wrapper = m_wrappers[modem->modemPath()]; | ||
3632 | 172 | if (m_knownSims.contains(wrapper->imsi())) | ||
3633 | 173 | { | ||
3634 | 174 | auto sim = m_knownSims[wrapper->imsi()]; | ||
3635 | 175 | sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); | ||
3636 | 176 | } | ||
3637 | 177 | m_wrappers.remove(modem->modemPath()); | ||
3638 | 178 | } | ||
3639 | 179 | } | ||
3640 | 180 | } | ||
3641 | 181 | |||
3642 | 182 | void ofonoSimPresentChanged(bool present) | ||
3643 | 183 | { | ||
3644 | 184 | auto wrapper = qobject_cast<QOfonoSimWrapper*>(sender()); | ||
3645 | 185 | if (!wrapper) { | ||
3646 | 186 | qWarning("casting failed."); | ||
3647 | 187 | } | ||
3648 | 188 | |||
3649 | 189 | if (!present) { | ||
3650 | 190 | if (m_knownSims.contains(wrapper->imsi())) | ||
3651 | 191 | { | ||
3652 | 192 | auto sim = m_knownSims[wrapper->imsi()]; | ||
3653 | 193 | sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); | ||
3654 | 194 | } | ||
3655 | 195 | } | ||
3656 | 196 | } | ||
3657 | 197 | |||
3658 | 198 | void ofonoSimReady(bool value) | ||
3659 | 199 | { | ||
3660 | 200 | if (!value) | ||
3661 | 201 | { | ||
3662 | 202 | // handled in present changed | ||
3663 | 203 | return; | ||
3664 | 204 | } | ||
3665 | 205 | |||
3666 | 206 | auto wrapper = qobject_cast<wwan::QOfonoSimWrapper*>(sender()); | ||
3667 | 207 | if (!wrapper) | ||
3668 | 208 | { | ||
3669 | 209 | qWarning("casting failed."); | ||
3670 | 210 | return; | ||
3671 | 211 | } | ||
3672 | 212 | |||
3673 | 213 | auto wrappers = m_wrappers; | ||
3674 | 214 | |||
3675 | 215 | bool found = false; | ||
3676 | 216 | for (auto i : m_knownSims.values()) | ||
3677 | 217 | { | ||
3678 | 218 | if (wrapper->imsi() == i->imsi()) | ||
3679 | 219 | { | ||
3680 | 220 | found = true; | ||
3681 | 221 | i->setOfonoSimManager(wrapper->ofonoSimManager()); | ||
3682 | 222 | break; | ||
3683 | 223 | } | ||
3684 | 224 | } | ||
3685 | 225 | if (!found) | ||
3686 | 226 | { | ||
3687 | 227 | auto sim = Sim::fromQOfonoSimWrapper(wrapper); | ||
3688 | 228 | connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Private::simDataRoamingEnabledChanged); | ||
3689 | 229 | wwan::Sim::saveToSettings(m_settings, sim); | ||
3690 | 230 | m_knownSims[sim->imsi()] = sim; | ||
3691 | 231 | m_settings->setValue("KnownSims", QVariant(m_knownSims.keys())); | ||
3692 | 232 | Q_EMIT p.simAdded(sim); | ||
3693 | 233 | } | ||
3694 | 234 | } | ||
3695 | 235 | |||
3696 | 236 | void simDataRoamingEnabledChanged(bool value) | ||
3697 | 237 | { | ||
3698 | 238 | Q_UNUSED(value) | ||
3699 | 239 | |||
3700 | 240 | auto sim_raw = qobject_cast<Sim*>(sender()); | ||
3701 | 241 | auto sim = m_knownSims[sim_raw->imsi()]; | ||
3702 | 242 | if (!sim) | ||
3703 | 243 | { | ||
3704 | 244 | qWarning("foobar"); | ||
3705 | 245 | return; | ||
3706 | 246 | } | ||
3707 | 247 | Sim::saveToSettings(m_settings, sim); | ||
3708 | 248 | } | ||
3709 | 249 | |||
3710 | 250 | }; | ||
3711 | 251 | |||
3712 | 252 | |||
3713 | 253 | |||
3714 | 254 | SimManager::SimManager() | ||
3715 | 255 | : d{new Private(*this)} | ||
3716 | 256 | { | ||
3717 | 257 | } | ||
3718 | 258 | |||
3719 | 259 | SimManager::~SimManager() | ||
3720 | 260 | {} | ||
3721 | 261 | |||
3722 | 262 | QList<Sim::Ptr> | ||
3723 | 263 | SimManager::knownSims() const | ||
3724 | 264 | { | ||
3725 | 265 | return d->m_knownSims.values(); | ||
3726 | 266 | } | ||
3727 | 267 | |||
3728 | 268 | } | ||
3729 | 269 | } | ||
3730 | 270 | |||
3731 | 271 | #include "sim-manager.moc" | ||
3732 | 0 | 272 | ||
3733 | === added file 'src/indicator/nmofono/wwan/sim-manager.h' | |||
3734 | --- src/indicator/nmofono/wwan/sim-manager.h 1970-01-01 00:00:00 +0000 | |||
3735 | +++ src/indicator/nmofono/wwan/sim-manager.h 2016-04-26 11:24:03 +0000 | |||
3736 | @@ -0,0 +1,56 @@ | |||
3737 | 1 | /* | ||
3738 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
3739 | 3 | * | ||
3740 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3741 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3742 | 6 | * by the Free Software Foundation. | ||
3743 | 7 | * | ||
3744 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3745 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3746 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3747 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3748 | 12 | * | ||
3749 | 13 | * You should have received a copy of the GNU General Public License along | ||
3750 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3751 | 15 | * | ||
3752 | 16 | * Authors: | ||
3753 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
3754 | 18 | */ | ||
3755 | 19 | |||
3756 | 20 | #pragma once | ||
3757 | 21 | |||
3758 | 22 | #include <QObject> | ||
3759 | 23 | #include <QSettings> | ||
3760 | 24 | |||
3761 | 25 | #include <memory> | ||
3762 | 26 | |||
3763 | 27 | #include "sim.h" | ||
3764 | 28 | |||
3765 | 29 | namespace nmofono | ||
3766 | 30 | { | ||
3767 | 31 | namespace wwan | ||
3768 | 32 | { | ||
3769 | 33 | |||
3770 | 34 | class SimManager : public QObject | ||
3771 | 35 | { | ||
3772 | 36 | Q_OBJECT | ||
3773 | 37 | |||
3774 | 38 | class Private; | ||
3775 | 39 | std::shared_ptr<Private> d; | ||
3776 | 40 | |||
3777 | 41 | public: | ||
3778 | 42 | |||
3779 | 43 | typedef std::shared_ptr<SimManager> Ptr; | ||
3780 | 44 | typedef std::weak_ptr<SimManager> WeakPtr; | ||
3781 | 45 | |||
3782 | 46 | SimManager(); | ||
3783 | 47 | ~SimManager(); | ||
3784 | 48 | |||
3785 | 49 | QList<Sim::Ptr> knownSims() const; | ||
3786 | 50 | |||
3787 | 51 | Q_SIGNALS: | ||
3788 | 52 | void simAdded(Sim::Ptr sim); | ||
3789 | 53 | }; | ||
3790 | 54 | |||
3791 | 55 | } | ||
3792 | 56 | } | ||
3793 | 0 | 57 | ||
3794 | === added file 'src/indicator/nmofono/wwan/sim.cpp' | |||
3795 | --- src/indicator/nmofono/wwan/sim.cpp 1970-01-01 00:00:00 +0000 | |||
3796 | +++ src/indicator/nmofono/wwan/sim.cpp 2016-04-26 11:24:03 +0000 | |||
3797 | @@ -0,0 +1,582 @@ | |||
3798 | 1 | /* | ||
3799 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
3800 | 3 | * | ||
3801 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3802 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3803 | 6 | * by the Free Software Foundation. | ||
3804 | 7 | * | ||
3805 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3806 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3807 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
3808 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3809 | 12 | * | ||
3810 | 13 | * You should have received a copy of the GNU General Public License along | ||
3811 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3812 | 15 | * | ||
3813 | 16 | * Authors: | ||
3814 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
3815 | 18 | */ | ||
3816 | 19 | |||
3817 | 20 | #include <nmofono/wwan/sim.h> | ||
3818 | 21 | |||
3819 | 22 | #include <ofono/dbus.h> | ||
3820 | 23 | |||
3821 | 24 | #define slots | ||
3822 | 25 | #include <qofono-qt5/qofonoconnectionmanager.h> | ||
3823 | 26 | #undef slots | ||
3824 | 27 | |||
3825 | 28 | using namespace std; | ||
3826 | 29 | |||
3827 | 30 | namespace nmofono | ||
3828 | 31 | { | ||
3829 | 32 | namespace wwan | ||
3830 | 33 | { | ||
3831 | 34 | namespace | ||
3832 | 35 | { | ||
3833 | 36 | |||
3834 | 37 | } | ||
3835 | 38 | |||
3836 | 39 | Sim::Ptr | ||
3837 | 40 | Sim::createFromSettings(QSettings *settings, const QString &imsi) | ||
3838 | 41 | { | ||
3839 | 42 | settings->beginGroup(QString("Sims/%1/").arg(imsi)); | ||
3840 | 43 | QVariant primaryPhoneNumber_var = settings->value("PrimaryPhoneNumber"); | ||
3841 | 44 | QVariant mcc_var = settings->value("Mcc"); | ||
3842 | 45 | QVariant mnc_var = settings->value("Mnc"); | ||
3843 | 46 | QVariant preferredLanguages_var = settings->value("PreferredLanguages"); | ||
3844 | 47 | QVariant dataRoamingEnabled_var = settings->value("DataRoamingEnabled"); | ||
3845 | 48 | settings->endGroup(); | ||
3846 | 49 | |||
3847 | 50 | if (imsi.isNull() || | ||
3848 | 51 | primaryPhoneNumber_var.isNull() || | ||
3849 | 52 | mcc_var.isNull() || | ||
3850 | 53 | mnc_var.isNull() || | ||
3851 | 54 | preferredLanguages_var.isNull() || | ||
3852 | 55 | dataRoamingEnabled_var.isNull()) | ||
3853 | 56 | { | ||
3854 | 57 | qWarning() << "Corrupt settings for SIM: " << imsi; | ||
3855 | 58 | settings->remove(QString("Sims/%1/").arg(imsi)); | ||
3856 | 59 | return Sim::Ptr(); | ||
3857 | 60 | } | ||
3858 | 61 | |||
3859 | 62 | return Sim::Ptr(new Sim(imsi, | ||
3860 | 63 | primaryPhoneNumber_var.toString(), | ||
3861 | 64 | mcc_var.toString(), | ||
3862 | 65 | mnc_var.toString(), | ||
3863 | 66 | preferredLanguages_var.toStringList(), | ||
3864 | 67 | dataRoamingEnabled_var.toBool())); | ||
3865 | 68 | } | ||
3866 | 69 | |||
3867 | 70 | void | ||
3868 | 71 | Sim::saveToSettings(QSettings *settings, Sim::Ptr sim) | ||
3869 | 72 | { | ||
3870 | 73 | settings->beginGroup(QString("Sims/%1/").arg(sim->imsi())); | ||
3871 | 74 | settings->setValue("PrimaryPhoneNumber", QVariant(sim->primaryPhoneNumber())); | ||
3872 | 75 | settings->setValue("Mcc", sim->mcc()); | ||
3873 | 76 | settings->setValue("Mnc", sim->mnc()); | ||
3874 | 77 | settings->setValue("PreferredLanguages", QVariant(sim->preferredLanguages())); | ||
3875 | 78 | settings->setValue("DataRoamingEnabled", sim->dataRoamingEnabled()); | ||
3876 | 79 | settings->endGroup(); | ||
3877 | 80 | settings->sync(); | ||
3878 | 81 | } | ||
3879 | 82 | |||
3880 | 83 | Sim::Ptr Sim::fromQOfonoSimWrapper(const QOfonoSimWrapper *wrapper) | ||
3881 | 84 | { | ||
3882 | 85 | auto sim = Sim::Ptr(new Sim(wrapper->imsi(), | ||
3883 | 86 | wrapper->phoneNumbers().first(), // default to the first number | ||
3884 | 87 | wrapper->mcc(), | ||
3885 | 88 | wrapper->mnc(), | ||
3886 | 89 | wrapper->preferredLanguages(), | ||
3887 | 90 | false)); | ||
3888 | 91 | sim->setOfonoSimManager(wrapper->ofonoSimManager()); | ||
3889 | 92 | return sim; | ||
3890 | 93 | } | ||
3891 | 94 | |||
3892 | 95 | class Sim::Private : public QObject, public std::enable_shared_from_this<Private> | ||
3893 | 96 | { | ||
3894 | 97 | Q_OBJECT | ||
3895 | 98 | |||
3896 | 99 | public: | ||
3897 | 100 | |||
3898 | 101 | Sim& p; | ||
3899 | 102 | |||
3900 | 103 | Sim::PinType m_requiredPin; | ||
3901 | 104 | RetriesType m_retries; | ||
3902 | 105 | Sim::Status m_status = Sim::Status::missing; | ||
3903 | 106 | |||
3904 | 107 | bool m_requiredPinSet = false; | ||
3905 | 108 | bool m_retriesSet = false; | ||
3906 | 109 | bool m_statusSet = false; | ||
3907 | 110 | |||
3908 | 111 | int m_index = -1; | ||
3909 | 112 | |||
3910 | 113 | QString m_simIdentifier; | ||
3911 | 114 | |||
3912 | 115 | shared_ptr<QOfonoSimManager> m_simManager; | ||
3913 | 116 | shared_ptr<QOfonoConnectionManager> m_connManager; | ||
3914 | 117 | |||
3915 | 118 | bool m_shouldTriggerUnlock = false; | ||
3916 | 119 | |||
3917 | 120 | QSet<QString> m_interfaces; | ||
3918 | 121 | |||
3919 | 122 | QTimer m_updatedTimer; | ||
3920 | 123 | |||
3921 | 124 | QString m_imsi; | ||
3922 | 125 | QString m_primaryPhoneNumber; | ||
3923 | 126 | QString m_mcc; | ||
3924 | 127 | QString m_mnc; | ||
3925 | 128 | QStringList m_preferredLanguages; | ||
3926 | 129 | bool m_dataRoamingEnabled; | ||
3927 | 130 | bool m_mobileDataEnabled = false; | ||
3928 | 131 | |||
3929 | 132 | bool m_locked = false; | ||
3930 | 133 | |||
3931 | 134 | Private(Sim &parent) | ||
3932 | 135 | : p(parent) | ||
3933 | 136 | { | ||
3934 | 137 | } | ||
3935 | 138 | |||
3936 | 139 | Private(Sim& parent, shared_ptr<QOfonoSimManager> simmgr) | ||
3937 | 140 | : p(parent) | ||
3938 | 141 | { | ||
3939 | 142 | simManagerChanged(simmgr); | ||
3940 | 143 | |||
3941 | 144 | |||
3942 | 145 | /// @todo hook up with system-settings to allow changing the identifier. | ||
3943 | 146 | if (m_simIdentifier.isEmpty()) | ||
3944 | 147 | { | ||
3945 | 148 | setSimIdentifier(m_primaryPhoneNumber); | ||
3946 | 149 | } | ||
3947 | 150 | |||
3948 | 151 | // Throttle the updates using a timer | ||
3949 | 152 | m_updatedTimer.setInterval(0); | ||
3950 | 153 | m_updatedTimer.setSingleShot(true); | ||
3951 | 154 | connect(&m_updatedTimer, &QTimer::timeout, this, &Private::fireUpdate); | ||
3952 | 155 | } | ||
3953 | 156 | |||
3954 | 157 | public Q_SLOTS: | ||
3955 | 158 | |||
3956 | 159 | void fireUpdate() | ||
3957 | 160 | { | ||
3958 | 161 | Q_EMIT p.updated(p); | ||
3959 | 162 | |||
3960 | 163 | if (p.isReadyToUnlock() && m_shouldTriggerUnlock) | ||
3961 | 164 | { | ||
3962 | 165 | m_shouldTriggerUnlock = false; | ||
3963 | 166 | Q_EMIT p.readyToUnlock(p.ofonoPath()); | ||
3964 | 167 | } | ||
3965 | 168 | } | ||
3966 | 169 | |||
3967 | 170 | void simManagerChanged(shared_ptr<QOfonoSimManager> simmgr) | ||
3968 | 171 | { | ||
3969 | 172 | if (m_simManager == simmgr) | ||
3970 | 173 | { | ||
3971 | 174 | return; | ||
3972 | 175 | } | ||
3973 | 176 | |||
3974 | 177 | m_simManager = simmgr; | ||
3975 | 178 | if (m_simManager) | ||
3976 | 179 | { | ||
3977 | 180 | connect(m_simManager.get(), | ||
3978 | 181 | &QOfonoSimManager::pinRequiredChanged, this, | ||
3979 | 182 | &Private::update); | ||
3980 | 183 | |||
3981 | 184 | connect(m_simManager.get(), | ||
3982 | 185 | &QOfonoSimManager::pinRetriesChanged, this, | ||
3983 | 186 | &Private::update); | ||
3984 | 187 | |||
3985 | 188 | connect(m_simManager.get(), | ||
3986 | 189 | &QOfonoSimManager::enterPinComplete, this, | ||
3987 | 190 | &Private::enterPinComplete); | ||
3988 | 191 | |||
3989 | 192 | connect(m_simManager.get(), | ||
3990 | 193 | &QOfonoSimManager::resetPinComplete, this, | ||
3991 | 194 | &Private::resetPinComplete); | ||
3992 | 195 | } | ||
3993 | 196 | |||
3994 | 197 | update(); | ||
3995 | 198 | |||
3996 | 199 | Q_EMIT p.presentChanged(m_simManager.get() != nullptr); | ||
3997 | 200 | } | ||
3998 | 201 | |||
3999 | 202 | void connManagerChanged(shared_ptr<QOfonoConnectionManager> connmgr) | ||
4000 | 203 | { | ||
4001 | 204 | if (m_connManager == connmgr) | ||
4002 | 205 | { | ||
4003 | 206 | return; | ||
4004 | 207 | } | ||
4005 | 208 | |||
4006 | 209 | m_connManager = connmgr; | ||
4007 | 210 | if (m_connManager) | ||
4008 | 211 | { | ||
4009 | 212 | connect(m_connManager.get(), | ||
4010 | 213 | &QOfonoConnectionManager::poweredChanged, this, | ||
4011 | 214 | &Private::update); | ||
4012 | 215 | connect(m_connManager.get(), | ||
4013 | 216 | &QOfonoConnectionManager::roamingAllowedChanged, this, | ||
4014 | 217 | &Private::update); | ||
4015 | 218 | |||
4016 | 219 | m_connManager->setPowered(m_mobileDataEnabled); | ||
4017 | 220 | m_connManager->setRoamingAllowed(m_dataRoamingEnabled); | ||
4018 | 221 | } | ||
4019 | 222 | |||
4020 | 223 | update(); | ||
4021 | 224 | } | ||
4022 | 225 | |||
4023 | 226 | void update() | ||
4024 | 227 | { | ||
4025 | 228 | if (m_simManager) { | ||
4026 | 229 | // update requiredPin | ||
4027 | 230 | switch(m_simManager->pinRequired()) | ||
4028 | 231 | { | ||
4029 | 232 | case QOfonoSimManager::PinType::NoPin: | ||
4030 | 233 | setRequiredPin(PinType::none); | ||
4031 | 234 | break; | ||
4032 | 235 | case QOfonoSimManager::PinType::SimPin: | ||
4033 | 236 | setRequiredPin(PinType::pin); | ||
4034 | 237 | break; | ||
4035 | 238 | case QOfonoSimManager::PinType::SimPuk: | ||
4036 | 239 | setRequiredPin(PinType::puk); | ||
4037 | 240 | break; | ||
4038 | 241 | default: | ||
4039 | 242 | throw std::runtime_error("Ofono requires a PIN we have not been prepared to handle (" + | ||
4040 | 243 | to_string(m_simManager->pinRequired()) + | ||
4041 | 244 | "). Bailing out."); | ||
4042 | 245 | } | ||
4043 | 246 | |||
4044 | 247 | m_requiredPinSet = true; | ||
4045 | 248 | |||
4046 | 249 | bool retriesWasSet = true; | ||
4047 | 250 | // update retries | ||
4048 | 251 | RetriesType tmp; | ||
4049 | 252 | QVariantMap retries = m_simManager->pinRetries(); | ||
4050 | 253 | QMapIterator<QString, QVariant> i(retries); | ||
4051 | 254 | while (i.hasNext()) { | ||
4052 | 255 | i.next(); | ||
4053 | 256 | QOfonoSimManager::PinType type = (QOfonoSimManager::PinType) i.key().toInt(); | ||
4054 | 257 | int count = i.value().toInt(); | ||
4055 | 258 | if (count < 0) | ||
4056 | 259 | { | ||
4057 | 260 | retriesWasSet = false; | ||
4058 | 261 | } | ||
4059 | 262 | switch(type) | ||
4060 | 263 | { | ||
4061 | 264 | case QOfonoSimManager::PinType::SimPin: | ||
4062 | 265 | tmp[Sim::PinType::pin] = count; | ||
4063 | 266 | break; | ||
4064 | 267 | case QOfonoSimManager::PinType::SimPuk: | ||
4065 | 268 | tmp[Sim::PinType::puk] = count; | ||
4066 | 269 | break; | ||
4067 | 270 | default: | ||
4068 | 271 | break; | ||
4069 | 272 | } | ||
4070 | 273 | } | ||
4071 | 274 | setRetries(tmp); | ||
4072 | 275 | |||
4073 | 276 | m_retriesSet = retriesWasSet; | ||
4074 | 277 | |||
4075 | 278 | } else { | ||
4076 | 279 | setRequiredPin(PinType::none); | ||
4077 | 280 | setRetries({}); | ||
4078 | 281 | |||
4079 | 282 | m_requiredPinSet = false; | ||
4080 | 283 | m_retriesSet = false; | ||
4081 | 284 | } | ||
4082 | 285 | |||
4083 | 286 | if (m_connManager) | ||
4084 | 287 | { | ||
4085 | 288 | bool powered = m_connManager->powered(); | ||
4086 | 289 | bool roamingAllowed = m_connManager->roamingAllowed(); | ||
4087 | 290 | |||
4088 | 291 | /* | ||
4089 | 292 | * Connectivity Service is the policy manager for the system. | ||
4090 | 293 | * If ofono has different settings force them back to stored values. | ||
4091 | 294 | */ | ||
4092 | 295 | if (m_mobileDataEnabled != powered) | ||
4093 | 296 | { | ||
4094 | 297 | m_connManager->setPowered(m_mobileDataEnabled); | ||
4095 | 298 | } | ||
4096 | 299 | if (m_dataRoamingEnabled != roamingAllowed) | ||
4097 | 300 | { | ||
4098 | 301 | m_connManager->setRoamingAllowed(m_dataRoamingEnabled); | ||
4099 | 302 | } | ||
4100 | 303 | } | ||
4101 | 304 | else | ||
4102 | 305 | { | ||
4103 | 306 | /* empty */ | ||
4104 | 307 | } | ||
4105 | 308 | } | ||
4106 | 309 | |||
4107 | 310 | void enterPinComplete(QOfonoSimManager::Error error, const QString &errorString) | ||
4108 | 311 | { | ||
4109 | 312 | if (error == QOfonoSimManager::Error::NoError) | ||
4110 | 313 | { | ||
4111 | 314 | Q_EMIT p.enterPinSuceeded(); | ||
4112 | 315 | } | ||
4113 | 316 | else | ||
4114 | 317 | { | ||
4115 | 318 | Q_EMIT p.enterPinFailed(errorString); | ||
4116 | 319 | } | ||
4117 | 320 | } | ||
4118 | 321 | |||
4119 | 322 | void resetPinComplete(QOfonoSimManager::Error error, const QString &errorString) | ||
4120 | 323 | { | ||
4121 | 324 | if (error == QOfonoSimManager::Error::NoError) | ||
4122 | 325 | { | ||
4123 | 326 | Q_EMIT p.resetPinSuceeded(); | ||
4124 | 327 | } | ||
4125 | 328 | else | ||
4126 | 329 | { | ||
4127 | 330 | Q_EMIT p.resetPinFailed(errorString); | ||
4128 | 331 | } | ||
4129 | 332 | } | ||
4130 | 333 | |||
4131 | 334 | void setSimIdentifier(const QString& simIdentifier) | ||
4132 | 335 | { | ||
4133 | 336 | if (m_simIdentifier == simIdentifier) | ||
4134 | 337 | { | ||
4135 | 338 | return; | ||
4136 | 339 | } | ||
4137 | 340 | |||
4138 | 341 | m_simIdentifier = simIdentifier; | ||
4139 | 342 | Q_EMIT p.simIdentifierUpdated(m_simIdentifier); | ||
4140 | 343 | } | ||
4141 | 344 | |||
4142 | 345 | void setRequiredPin(Sim::PinType requiredPin) | ||
4143 | 346 | { | ||
4144 | 347 | if (m_requiredPin == requiredPin) | ||
4145 | 348 | { | ||
4146 | 349 | return; | ||
4147 | 350 | } | ||
4148 | 351 | |||
4149 | 352 | m_requiredPin = requiredPin; | ||
4150 | 353 | Q_EMIT p.requiredPinUpdated(m_requiredPin); | ||
4151 | 354 | } | ||
4152 | 355 | |||
4153 | 356 | void setRetries(const RetriesType& retries) | ||
4154 | 357 | { | ||
4155 | 358 | if (m_retries == retries) | ||
4156 | 359 | { | ||
4157 | 360 | return; | ||
4158 | 361 | } | ||
4159 | 362 | |||
4160 | 363 | m_retries = retries; | ||
4161 | 364 | Q_EMIT p.retriesUpdated(); | ||
4162 | 365 | } | ||
4163 | 366 | |||
4164 | 367 | void setStatus(Sim::Status value) | ||
4165 | 368 | { | ||
4166 | 369 | if (m_status == value) | ||
4167 | 370 | { | ||
4168 | 371 | return; | ||
4169 | 372 | } | ||
4170 | 373 | |||
4171 | 374 | m_status = value; | ||
4172 | 375 | Q_EMIT p.statusUpdated(); | ||
4173 | 376 | } | ||
4174 | 377 | |||
4175 | 378 | void setOfono(std::shared_ptr<QOfonoSimManager> simmgr) | ||
4176 | 379 | { | ||
4177 | 380 | simManagerChanged(simmgr); | ||
4178 | 381 | if (simmgr) | ||
4179 | 382 | { | ||
4180 | 383 | m_connManager = std::make_shared<QOfonoConnectionManager>(this); | ||
4181 | 384 | connManagerChanged(m_connManager); | ||
4182 | 385 | } | ||
4183 | 386 | else | ||
4184 | 387 | { | ||
4185 | 388 | m_connManager = std::shared_ptr<QOfonoConnectionManager>(); | ||
4186 | 389 | connManagerChanged(m_connManager); | ||
4187 | 390 | } | ||
4188 | 391 | } | ||
4189 | 392 | |||
4190 | 393 | |||
4191 | 394 | }; | ||
4192 | 395 | |||
4193 | 396 | Sim::Sim(const QString &imsi, | ||
4194 | 397 | const QString &primaryPhoneNumber, | ||
4195 | 398 | const QString &mcc, | ||
4196 | 399 | const QString &mnc, | ||
4197 | 400 | const QStringList &preferredLanguages, | ||
4198 | 401 | bool dataRoamingEnabled) | ||
4199 | 402 | : d{new Private(*this)} | ||
4200 | 403 | { | ||
4201 | 404 | d->m_imsi = imsi; | ||
4202 | 405 | d->m_primaryPhoneNumber = primaryPhoneNumber; | ||
4203 | 406 | d->m_mcc = mcc; | ||
4204 | 407 | d->m_mnc = mnc; | ||
4205 | 408 | d->m_preferredLanguages = preferredLanguages; | ||
4206 | 409 | d->m_dataRoamingEnabled = dataRoamingEnabled; | ||
4207 | 410 | } | ||
4208 | 411 | |||
4209 | 412 | Sim::~Sim() | ||
4210 | 413 | {} | ||
4211 | 414 | |||
4212 | 415 | void | ||
4213 | 416 | Sim::enterPin(PinType type, const QString &pin) | ||
4214 | 417 | { | ||
4215 | 418 | if (!d->m_simManager) | ||
4216 | 419 | { | ||
4217 | 420 | throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager."); | ||
4218 | 421 | } | ||
4219 | 422 | |||
4220 | 423 | switch(type) { | ||
4221 | 424 | case PinType::none: | ||
4222 | 425 | break; | ||
4223 | 426 | case PinType::pin: | ||
4224 | 427 | d->m_simManager->enterPin(QOfonoSimManager::PinType::SimPin, | ||
4225 | 428 | pin); | ||
4226 | 429 | break; | ||
4227 | 430 | case PinType::puk: | ||
4228 | 431 | d->m_simManager->enterPin(QOfonoSimManager::PinType::SimPuk, | ||
4229 | 432 | pin); | ||
4230 | 433 | break; | ||
4231 | 434 | } | ||
4232 | 435 | } | ||
4233 | 436 | |||
4234 | 437 | |||
4235 | 438 | void | ||
4236 | 439 | Sim::resetPin(PinType type, const QString &puk, const QString &pin) | ||
4237 | 440 | { | ||
4238 | 441 | if (!d->m_simManager) { | ||
4239 | 442 | throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager."); | ||
4240 | 443 | } | ||
4241 | 444 | |||
4242 | 445 | switch(type) { | ||
4243 | 446 | case PinType::none: | ||
4244 | 447 | break; | ||
4245 | 448 | case PinType::puk: | ||
4246 | 449 | d->m_simManager->resetPin(QOfonoSimManager::PinType::SimPuk, | ||
4247 | 450 | puk, | ||
4248 | 451 | pin); | ||
4249 | 452 | break; | ||
4250 | 453 | default: | ||
4251 | 454 | throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": Not Supported."); | ||
4252 | 455 | } | ||
4253 | 456 | } | ||
4254 | 457 | |||
4255 | 458 | Sim::PinType | ||
4256 | 459 | Sim::requiredPin() const | ||
4257 | 460 | { | ||
4258 | 461 | return d->m_requiredPin; | ||
4259 | 462 | } | ||
4260 | 463 | |||
4261 | 464 | const Sim::RetriesType& | ||
4262 | 465 | Sim::retries() const | ||
4263 | 466 | { | ||
4264 | 467 | return d->m_retries; | ||
4265 | 468 | } | ||
4266 | 469 | |||
4267 | 470 | const QString& | ||
4268 | 471 | Sim::simIdentifier() const | ||
4269 | 472 | { | ||
4270 | 473 | return d->m_simIdentifier; | ||
4271 | 474 | } | ||
4272 | 475 | |||
4273 | 476 | bool | ||
4274 | 477 | Sim::isReadyToUnlock() const | ||
4275 | 478 | { | ||
4276 | 479 | return d->m_statusSet && d->m_requiredPinSet && d->m_retriesSet | ||
4277 | 480 | && (d->m_requiredPin != PinType::none); | ||
4278 | 481 | } | ||
4279 | 482 | |||
4280 | 483 | void | ||
4281 | 484 | Sim::notifyWhenReadyToUnlock() | ||
4282 | 485 | { | ||
4283 | 486 | d->m_shouldTriggerUnlock = true; | ||
4284 | 487 | } | ||
4285 | 488 | |||
4286 | 489 | |||
4287 | 490 | Sim::Status Sim::status() const | ||
4288 | 491 | { | ||
4289 | 492 | return d->m_status; | ||
4290 | 493 | } | ||
4291 | 494 | |||
4292 | 495 | QString Sim::imsi() const | ||
4293 | 496 | { | ||
4294 | 497 | return d->m_imsi; | ||
4295 | 498 | } | ||
4296 | 499 | |||
4297 | 500 | QString Sim::primaryPhoneNumber() const | ||
4298 | 501 | { | ||
4299 | 502 | return d->m_primaryPhoneNumber; | ||
4300 | 503 | } | ||
4301 | 504 | |||
4302 | 505 | bool Sim::locked() const | ||
4303 | 506 | { | ||
4304 | 507 | return d->m_locked; | ||
4305 | 508 | } | ||
4306 | 509 | |||
4307 | 510 | bool Sim::present() const | ||
4308 | 511 | { | ||
4309 | 512 | return d->m_simManager.get() != nullptr; | ||
4310 | 513 | } | ||
4311 | 514 | |||
4312 | 515 | QString Sim::mcc() const | ||
4313 | 516 | { | ||
4314 | 517 | return d->m_mcc; | ||
4315 | 518 | } | ||
4316 | 519 | |||
4317 | 520 | QString Sim::mnc() const | ||
4318 | 521 | { | ||
4319 | 522 | return d->m_mnc; | ||
4320 | 523 | } | ||
4321 | 524 | |||
4322 | 525 | QList<QString> Sim::preferredLanguages() const | ||
4323 | 526 | { | ||
4324 | 527 | return d->m_preferredLanguages; | ||
4325 | 528 | } | ||
4326 | 529 | |||
4327 | 530 | bool Sim::dataRoamingEnabled() const | ||
4328 | 531 | { | ||
4329 | 532 | return d->m_dataRoamingEnabled; | ||
4330 | 533 | } | ||
4331 | 534 | |||
4332 | 535 | void Sim::setDataRoamingEnabled(bool value) | ||
4333 | 536 | { | ||
4334 | 537 | if (d->m_dataRoamingEnabled == value) | ||
4335 | 538 | return; | ||
4336 | 539 | d->m_dataRoamingEnabled = value; | ||
4337 | 540 | Q_EMIT dataRoamingEnabledChanged(value); | ||
4338 | 541 | } | ||
4339 | 542 | |||
4340 | 543 | bool Sim::mobileDataEnabled() const | ||
4341 | 544 | { | ||
4342 | 545 | return d->m_mobileDataEnabled; | ||
4343 | 546 | } | ||
4344 | 547 | |||
4345 | 548 | void Sim::setMobileDataEnabled(bool value) | ||
4346 | 549 | { | ||
4347 | 550 | if (d->m_mobileDataEnabled == value) | ||
4348 | 551 | return; | ||
4349 | 552 | d->m_mobileDataEnabled = value; | ||
4350 | 553 | if (d->m_connManager) | ||
4351 | 554 | { | ||
4352 | 555 | d->m_connManager->setPowered(d->m_mobileDataEnabled); | ||
4353 | 556 | } | ||
4354 | 557 | Q_EMIT mobileDataEnabledChanged(value); | ||
4355 | 558 | } | ||
4356 | 559 | |||
4357 | 560 | void Sim::unlock() | ||
4358 | 561 | { | ||
4359 | 562 | |||
4360 | 563 | } | ||
4361 | 564 | |||
4362 | 565 | QString Sim::ofonoPath() const | ||
4363 | 566 | { | ||
4364 | 567 | if (d->m_simManager) { | ||
4365 | 568 | return d->m_simManager->objectPath(); | ||
4366 | 569 | } | ||
4367 | 570 | return QString(); | ||
4368 | 571 | } | ||
4369 | 572 | |||
4370 | 573 | void Sim::setOfonoSimManager(std::shared_ptr<QOfonoSimManager> simmgr) | ||
4371 | 574 | { | ||
4372 | 575 | d->setOfono(simmgr); | ||
4373 | 576 | } | ||
4374 | 577 | |||
4375 | 578 | |||
4376 | 579 | } | ||
4377 | 580 | } | ||
4378 | 581 | |||
4379 | 582 | #include "sim.moc" | ||
4380 | 0 | 583 | ||
4381 | === added file 'src/indicator/nmofono/wwan/sim.h' | |||
4382 | --- src/indicator/nmofono/wwan/sim.h 1970-01-01 00:00:00 +0000 | |||
4383 | +++ src/indicator/nmofono/wwan/sim.h 2016-04-26 11:24:03 +0000 | |||
4384 | @@ -0,0 +1,182 @@ | |||
4385 | 1 | /* | ||
4386 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
4387 | 3 | * | ||
4388 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
4389 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
4390 | 6 | * by the Free Software Foundation. | ||
4391 | 7 | * | ||
4392 | 8 | * This program is distributed in the hope that it will be useful, but | ||
4393 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
4394 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
4395 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
4396 | 12 | * | ||
4397 | 13 | * You should have received a copy of the GNU General Public License along | ||
4398 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4399 | 15 | * | ||
4400 | 16 | * Authors: | ||
4401 | 17 | * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> | ||
4402 | 18 | */ | ||
4403 | 19 | |||
4404 | 20 | #pragma once | ||
4405 | 21 | |||
4406 | 22 | #include <QObject> | ||
4407 | 23 | #include <QSettings> | ||
4408 | 24 | |||
4409 | 25 | #include <memory> | ||
4410 | 26 | |||
4411 | 27 | #define slots | ||
4412 | 28 | #include <qofono-qt5/qofonomodem.h> | ||
4413 | 29 | #include <qofono-qt5/qofonosimmanager.h> | ||
4414 | 30 | #undef slots | ||
4415 | 31 | |||
4416 | 32 | #include <nmofono/wwan/qofono-sim-wrapper.h> | ||
4417 | 33 | |||
4418 | 34 | class QOfonoModem; | ||
4419 | 35 | |||
4420 | 36 | namespace nmofono | ||
4421 | 37 | { | ||
4422 | 38 | class ManagerImpl; | ||
4423 | 39 | |||
4424 | 40 | namespace wwan | ||
4425 | 41 | { | ||
4426 | 42 | |||
4427 | 43 | class Sim : public QObject | ||
4428 | 44 | { | ||
4429 | 45 | Q_OBJECT | ||
4430 | 46 | |||
4431 | 47 | class Private; | ||
4432 | 48 | std::shared_ptr<Private> d; | ||
4433 | 49 | |||
4434 | 50 | public: | ||
4435 | 51 | |||
4436 | 52 | typedef std::shared_ptr<Sim> Ptr; | ||
4437 | 53 | typedef std::weak_ptr<Sim> WeakPtr; | ||
4438 | 54 | |||
4439 | 55 | enum class PinType | ||
4440 | 56 | { | ||
4441 | 57 | none, | ||
4442 | 58 | pin, | ||
4443 | 59 | puk | ||
4444 | 60 | }; | ||
4445 | 61 | |||
4446 | 62 | enum class Status | ||
4447 | 63 | { | ||
4448 | 64 | missing, | ||
4449 | 65 | error, | ||
4450 | 66 | locked, | ||
4451 | 67 | permanentlyLocked, | ||
4452 | 68 | ready, | ||
4453 | 69 | not_available | ||
4454 | 70 | }; | ||
4455 | 71 | |||
4456 | 72 | Sim() = delete; | ||
4457 | 73 | |||
4458 | 74 | static Sim::Ptr createFromSettings(QSettings*, const QString &imsi); | ||
4459 | 75 | static void saveToSettings(QSettings *, Sim::Ptr); | ||
4460 | 76 | |||
4461 | 77 | static Sim::Ptr fromQOfonoSimWrapper(const QOfonoSimWrapper *wrapper); | ||
4462 | 78 | |||
4463 | 79 | private: | ||
4464 | 80 | Sim(const QString &imsi, | ||
4465 | 81 | const QString &primaryPhoneNumber, | ||
4466 | 82 | const QString &mcc, | ||
4467 | 83 | const QString &mnc, | ||
4468 | 84 | const QStringList &preferredLanguages, | ||
4469 | 85 | bool dataRoamingEnabled); | ||
4470 | 86 | |||
4471 | 87 | public: | ||
4472 | 88 | ~Sim(); | ||
4473 | 89 | void setOfonoSimManager(std::shared_ptr<QOfonoSimManager> simmgr); | ||
4474 | 90 | |||
4475 | 91 | |||
4476 | 92 | Q_PROPERTY(Sim::PinType requiredPin READ requiredPin NOTIFY requiredPinUpdated) | ||
4477 | 93 | PinType requiredPin() const; | ||
4478 | 94 | |||
4479 | 95 | typedef std::map<Sim::PinType, int> RetriesType; | ||
4480 | 96 | Q_PROPERTY(RetriesType retries READ retries NOTIFY retriesUpdated) | ||
4481 | 97 | const RetriesType &retries() const; | ||
4482 | 98 | |||
4483 | 99 | Q_PROPERTY(QString simIdentifier READ simIdentifier NOTIFY simIdentifierUpdated) | ||
4484 | 100 | const QString &simIdentifier() const; | ||
4485 | 101 | |||
4486 | 102 | Q_PROPERTY(Sim::Status status READ status NOTIFY statusUpdated) | ||
4487 | 103 | Status status() const; | ||
4488 | 104 | |||
4489 | 105 | Q_PROPERTY(QString imsi READ imsi CONSTANT) | ||
4490 | 106 | QString imsi() const; | ||
4491 | 107 | |||
4492 | 108 | Q_PROPERTY(QString primaryPhoneNumber READ primaryPhoneNumber CONSTANT) | ||
4493 | 109 | QString primaryPhoneNumber() const; | ||
4494 | 110 | |||
4495 | 111 | Q_PROPERTY(bool locked READ locked NOTIFY lockedChanged) | ||
4496 | 112 | bool locked() const; | ||
4497 | 113 | |||
4498 | 114 | Q_PROPERTY(bool present READ present NOTIFY presentChanged) | ||
4499 | 115 | bool present() const; | ||
4500 | 116 | |||
4501 | 117 | Q_PROPERTY(QString mcc READ mcc CONSTANT) | ||
4502 | 118 | QString mcc() const; | ||
4503 | 119 | |||
4504 | 120 | Q_PROPERTY(QString mnc READ mnc CONSTANT) | ||
4505 | 121 | QString mnc() const; | ||
4506 | 122 | |||
4507 | 123 | Q_PROPERTY(QList<QString> preferredLanguages READ preferredLanguages CONSTANT) | ||
4508 | 124 | QList<QString> preferredLanguages() const; | ||
4509 | 125 | |||
4510 | 126 | Q_PROPERTY(bool dataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled NOTIFY dataRoamingEnabledChanged) | ||
4511 | 127 | bool dataRoamingEnabled() const; | ||
4512 | 128 | void setDataRoamingEnabled(bool value); | ||
4513 | 129 | |||
4514 | 130 | Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged) | ||
4515 | 131 | bool mobileDataEnabled() const; | ||
4516 | 132 | void setMobileDataEnabled(bool value); | ||
4517 | 133 | |||
4518 | 134 | bool isReadyToUnlock() const; | ||
4519 | 135 | |||
4520 | 136 | void notifyWhenReadyToUnlock(); | ||
4521 | 137 | |||
4522 | 138 | void enterPin(PinType type, | ||
4523 | 139 | const QString &pin); | ||
4524 | 140 | |||
4525 | 141 | void resetPin(PinType type, | ||
4526 | 142 | const QString &puk, | ||
4527 | 143 | const QString &pin); | ||
4528 | 144 | |||
4529 | 145 | QString ofonoPath() const; | ||
4530 | 146 | |||
4531 | 147 | public Q_SLOTS: | ||
4532 | 148 | void unlock(); | ||
4533 | 149 | |||
4534 | 150 | Q_SIGNALS: | ||
4535 | 151 | |||
4536 | 152 | void requiredPinUpdated(PinType); | ||
4537 | 153 | |||
4538 | 154 | void retriesUpdated(); | ||
4539 | 155 | |||
4540 | 156 | void simIdentifierUpdated(const QString &); | ||
4541 | 157 | |||
4542 | 158 | void updated(const Sim& sim); | ||
4543 | 159 | |||
4544 | 160 | void enterPinSuceeded(); | ||
4545 | 161 | |||
4546 | 162 | void enterPinFailed(const QString& error); | ||
4547 | 163 | |||
4548 | 164 | void resetPinSuceeded(); | ||
4549 | 165 | |||
4550 | 166 | void resetPinFailed(const QString& error); | ||
4551 | 167 | |||
4552 | 168 | bool readyToUnlock(const QString& name); | ||
4553 | 169 | |||
4554 | 170 | void statusUpdated(); | ||
4555 | 171 | |||
4556 | 172 | void lockedChanged(bool value); | ||
4557 | 173 | |||
4558 | 174 | void presentChanged(bool value); | ||
4559 | 175 | |||
4560 | 176 | void dataRoamingEnabledChanged(bool value); | ||
4561 | 177 | |||
4562 | 178 | void mobileDataEnabledChanged(bool value); | ||
4563 | 179 | }; | ||
4564 | 180 | |||
4565 | 181 | } | ||
4566 | 182 | } | ||
4567 | 0 | 183 | ||
4568 | === modified file 'src/indicator/sections/wwan-section.cpp' | |||
4569 | --- src/indicator/sections/wwan-section.cpp 2016-02-12 14:25:16 +0000 | |||
4570 | +++ src/indicator/sections/wwan-section.cpp 2016-04-26 11:24:03 +0000 | |||
4571 | @@ -54,13 +54,14 @@ | |||
4572 | 54 | 54 | ||
4573 | 55 | Manager::Ptr m_manager; | 55 | Manager::Ptr m_manager; |
4574 | 56 | 56 | ||
4575 | 57 | SwitchItem::Ptr m_mobileDataSwitch; | ||
4576 | 57 | SwitchItem::Ptr m_hotspotSwitch; | 58 | SwitchItem::Ptr m_hotspotSwitch; |
4577 | 58 | TextItem::Ptr m_openCellularSettings; | 59 | TextItem::Ptr m_openCellularSettings; |
4578 | 59 | 60 | ||
4579 | 60 | QMap<wwan::Modem::Ptr, WwanLinkItem::Ptr> m_items; | 61 | QMap<wwan::Modem::Ptr, WwanLinkItem::Ptr> m_items; |
4580 | 61 | 62 | ||
4581 | 62 | Private() = delete; | 63 | Private() = delete; |
4583 | 63 | Private(Manager::Ptr modemManager, SwitchItem::Ptr hotspotSwitch); | 64 | Private(Manager::Ptr modemManager, SwitchItem::Ptr mobileDataSwitch ,SwitchItem::Ptr hotspotSwitch); |
4584 | 64 | 65 | ||
4585 | 65 | public Q_SLOTS: | 66 | public Q_SLOTS: |
4586 | 66 | void modemsChanged(); | 67 | void modemsChanged(); |
4587 | @@ -77,8 +78,8 @@ | |||
4588 | 77 | } | 78 | } |
4589 | 78 | }; | 79 | }; |
4590 | 79 | 80 | ||
4593 | 80 | WwanSection::Private::Private(Manager::Ptr modemManager, SwitchItem::Ptr hotspotSwitch) | 81 | WwanSection::Private::Private(Manager::Ptr modemManager, SwitchItem::Ptr mobileDataSwitch,SwitchItem::Ptr hotspotSwitch) |
4594 | 81 | : QObject(nullptr), m_manager{modemManager}, m_hotspotSwitch{hotspotSwitch} | 82 | : QObject(nullptr), m_manager{modemManager}, m_mobileDataSwitch{mobileDataSwitch}, m_hotspotSwitch{hotspotSwitch} |
4595 | 82 | { | 83 | { |
4596 | 83 | m_actionGroupMerger = make_shared<ActionGroupMerger>(); | 84 | m_actionGroupMerger = make_shared<ActionGroupMerger>(); |
4597 | 84 | m_menuMerger = make_shared<MenuMerger>(); | 85 | m_menuMerger = make_shared<MenuMerger>(); |
4598 | @@ -91,6 +92,9 @@ | |||
4599 | 91 | m_menuMerger->append(m_linkMenuMerger); | 92 | m_menuMerger->append(m_linkMenuMerger); |
4600 | 92 | m_menuMerger->append(m_bottomMenu); | 93 | m_menuMerger->append(m_bottomMenu); |
4601 | 93 | 94 | ||
4602 | 95 | m_upperMenu->append(m_mobileDataSwitch->menuItem()); | ||
4603 | 96 | m_actionGroupMerger->add(m_mobileDataSwitch->actionGroup()); | ||
4604 | 97 | |||
4605 | 94 | // have the modem list in their own section. | 98 | // have the modem list in their own section. |
4606 | 95 | m_topItem = MenuItem::newSection(m_menuMerger); | 99 | m_topItem = MenuItem::newSection(m_menuMerger); |
4607 | 96 | m_topMenu = make_shared<Menu>(); | 100 | m_topMenu = make_shared<Menu>(); |
4608 | @@ -186,8 +190,8 @@ | |||
4609 | 186 | } | 190 | } |
4610 | 187 | } | 191 | } |
4611 | 188 | 192 | ||
4614 | 189 | WwanSection::WwanSection(nmofono::Manager::Ptr manager, SwitchItem::Ptr hotspotSwitch) | 193 | WwanSection::WwanSection(nmofono::Manager::Ptr manager, SwitchItem::Ptr mobileDataSwitch, SwitchItem::Ptr hotspotSwitch) |
4615 | 190 | : d{new Private(manager, hotspotSwitch)} | 194 | : d{new Private(manager, mobileDataSwitch, hotspotSwitch)} |
4616 | 191 | { | 195 | { |
4617 | 192 | } | 196 | } |
4618 | 193 | 197 | ||
4619 | 194 | 198 | ||
4620 | === modified file 'src/indicator/sections/wwan-section.h' | |||
4621 | --- src/indicator/sections/wwan-section.h 2015-08-14 15:52:39 +0000 | |||
4622 | +++ src/indicator/sections/wwan-section.h 2016-04-26 11:24:03 +0000 | |||
4623 | @@ -30,7 +30,7 @@ | |||
4624 | 30 | 30 | ||
4625 | 31 | public: | 31 | public: |
4626 | 32 | typedef std::shared_ptr<WwanSection> Ptr; | 32 | typedef std::shared_ptr<WwanSection> Ptr; |
4628 | 33 | explicit WwanSection(nmofono::Manager::Ptr modemManager, SwitchItem::Ptr hotspotSwitch); | 33 | explicit WwanSection(nmofono::Manager::Ptr modemManager, SwitchItem::Ptr mobileDataSwitch, SwitchItem::Ptr hotspotSwitch); |
4629 | 34 | virtual ~WwanSection(); | 34 | virtual ~WwanSection(); |
4630 | 35 | 35 | ||
4631 | 36 | virtual ActionGroup::Ptr actionGroup(); | 36 | virtual ActionGroup::Ptr actionGroup(); |
4632 | 37 | 37 | ||
4633 | === modified file 'src/qdbus-stubs/dbus-types.h' | |||
4634 | --- src/qdbus-stubs/dbus-types.h 2015-11-20 13:14:50 +0000 | |||
4635 | +++ src/qdbus-stubs/dbus-types.h 2016-04-26 11:24:03 +0000 | |||
4636 | @@ -47,6 +47,19 @@ | |||
4637 | 47 | return path.arg(counter++); | 47 | return path.arg(counter++); |
4638 | 48 | } | 48 | } |
4639 | 49 | 49 | ||
4640 | 50 | inline QString modemPath(const QString &serial) | ||
4641 | 51 | { | ||
4642 | 52 | static QString path{"/com/ubuntu/connectivity1/modem/%1"}; | ||
4643 | 53 | return path.arg(serial); | ||
4644 | 54 | } | ||
4645 | 55 | |||
4646 | 56 | inline QString simPath(const QString &imsi) | ||
4647 | 57 | { | ||
4648 | 58 | static QString path{"/com/ubuntu/connectivity1/sim/%1"}; | ||
4649 | 59 | return path.arg(imsi); | ||
4650 | 60 | } | ||
4651 | 61 | |||
4652 | 62 | |||
4653 | 50 | static constexpr char const* WPASUPPLICANT_DBUS_NAME = "fi.w1.wpa_supplicant1"; | 63 | static constexpr char const* WPASUPPLICANT_DBUS_NAME = "fi.w1.wpa_supplicant1"; |
4654 | 51 | 64 | ||
4655 | 52 | static constexpr char const* WPASUPPLICANT_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"; | 65 | static constexpr char const* WPASUPPLICANT_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"; |
4656 | 53 | 66 | ||
4657 | === added file 'tests/data/phonesim/sim_general.xml' | |||
4658 | --- tests/data/phonesim/sim_general.xml 1970-01-01 00:00:00 +0000 | |||
4659 | +++ tests/data/phonesim/sim_general.xml 2016-04-26 11:24:03 +0000 | |||
4660 | @@ -0,0 +1,3677 @@ | |||
4661 | 1 | <?xml version="1.0"?> | ||
4662 | 2 | <simulator> | ||
4663 | 3 | |||
4664 | 4 | <!-- Phone simulator definition file for the "Qt Extended Pseudo Phone" --> | ||
4665 | 5 | |||
4666 | 6 | <!-- Note: dialing 199 will cause a dialback to simulate an incoming call --> | ||
4667 | 7 | <!-- Note: dialing 177 will cause a dialback to simulate an incoming call, and hangup after 5 seconds --> | ||
4668 | 8 | <!-- Note: dialing 166 will accept the incoming call and hangup up after 5 seconds--> | ||
4669 | 9 | <!-- Note: dialing 155 will elicit a 'BUSY' response from the recipient--> | ||
4670 | 10 | <!-- Note: dialing 05123xx cause an MT disconnect of the connected call after xx seconds--> | ||
4671 | 11 | <!-- Note: dialing 06123xx cause an automatic accept after xx seconds--> | ||
4672 | 12 | |||
4673 | 13 | <!-- Initialize state variables --> | ||
4674 | 14 | |||
4675 | 15 | <!-- Advice of charge --> | ||
4676 | 16 | <!-- Call Meter --> | ||
4677 | 17 | <set name="AOC" value="000000"/> | ||
4678 | 18 | |||
4679 | 19 | <!-- Call Meter reporting --> | ||
4680 | 20 | <set name="AOCMODE" value="1"/> | ||
4681 | 21 | |||
4682 | 22 | <!-- Accumulated Call Meter --> | ||
4683 | 23 | <set name="ACM" value="000480"/> | ||
4684 | 24 | |||
4685 | 25 | <!-- Accumulated Call Meter Maximum --> | ||
4686 | 26 | <set name="ACMMAX" value="000500"/> | ||
4687 | 27 | |||
4688 | 28 | <!-- Price per Unit and Currency --> | ||
4689 | 29 | <set name="PPU" value='GBP","2.66'/> | ||
4690 | 30 | |||
4691 | 31 | <!-- Battery Capacity | ||
4692 | 32 | first value | ||
4693 | 33 | 0-powered by battery | ||
4694 | 34 | 1-battery connected, powered by charger | ||
4695 | 35 | 2-no battery. | ||
4696 | 36 | |||
4697 | 37 | second value is percentage battery remaining. | ||
4698 | 38 | 0-exhausted | ||
4699 | 39 | 1-99-partial charge | ||
4700 | 40 | 100-fully charged. | ||
4701 | 41 | --> | ||
4702 | 42 | <set name="BC" value="0,100"/> | ||
4703 | 43 | |||
4704 | 44 | <!-- Signal Quality --> | ||
4705 | 45 | <set name="SQ" value="31,99"/> | ||
4706 | 46 | |||
4707 | 47 | <!-- Manufacturer --> | ||
4708 | 48 | <set name="GMI" value="Ubuntu"/> | ||
4709 | 49 | |||
4710 | 50 | <!-- Model --> | ||
4711 | 51 | <set name="GMM" value="Synthetic Device"/> | ||
4712 | 52 | |||
4713 | 53 | <!-- Revision --> | ||
4714 | 54 | <set name="GMR" value="REV1"/> | ||
4715 | 55 | |||
4716 | 56 | <!-- Serial number --> | ||
4717 | 57 | <set name="GSN" value="5647382910"/> | ||
4718 | 58 | |||
4719 | 59 | <!-- SIM card id --> | ||
4720 | 60 | <set name="IMSI" value="123123123"/> | ||
4721 | 61 | |||
4722 | 62 | <!-- Identifier for ATI command --> | ||
4723 | 63 | <set name="ID" value="Ubuntu Phone Simulator"/> | ||
4724 | 64 | |||
4725 | 65 | <!-- Character set --> | ||
4726 | 66 | <set name="SCS" value="IRA"/> | ||
4727 | 67 | |||
4728 | 68 | <!-- Type of address (local = 129, international = 145) --> | ||
4729 | 69 | <set name="STA" value="129"/> | ||
4730 | 70 | |||
4731 | 71 | <!-- Service reporting control flag --> | ||
4732 | 72 | <set name="CR" value="0"/> | ||
4733 | 73 | |||
4734 | 74 | <!-- Cellular result code control flag --> | ||
4735 | 75 | <set name="CRC" value="0"/> | ||
4736 | 76 | |||
4737 | 77 | <!-- Extended error message string --> | ||
4738 | 78 | <set name="ERR" value="EXTENDED ERROR STRING"/> | ||
4739 | 79 | |||
4740 | 80 | <!-- Network registration presentation flag --> | ||
4741 | 81 | <set name="REG" value="1,0"/> | ||
4742 | 82 | |||
4743 | 83 | <!-- GPRS network registration presentation flag --> | ||
4744 | 84 | <set name="GREG" value="0"/> | ||
4745 | 85 | |||
4746 | 86 | <!-- Mobile phone operator selection mode (0=auto, 1=manual, 2=deregister, 3=set only <format>, 4=manual / automatic) --> | ||
4747 | 87 | <set name="OPMODE" value="0"/> | ||
4748 | 88 | |||
4749 | 89 | <!-- Mobile phone operator selection format (0=long alphanumeric, 1=short alphanumeric, 2=numeric --> | ||
4750 | 90 | <set name="OPFORMAT" value="0"/> | ||
4751 | 91 | |||
4752 | 92 | <!-- GCF Operator List, format <status(1:available,2:current,3:forbidden)>,"<alphanum.operator name>","<short operator name>","<MCC/MNC num>"--> | ||
4753 | 93 | <set name="OP1" value="T-Ubuntu"/> | ||
4754 | 94 | <set name="OP1PLMN" value="23401"/> | ||
4755 | 95 | <set name="OP1STATE" value="2"/> | ||
4756 | 96 | |||
4757 | 97 | <set name="OP2" value="Maybe Forbidden Net"/> | ||
4758 | 98 | <set name="OP2PLMN" value="23402"/> | ||
4759 | 99 | <set name="OP2STATE" value="3"/> | ||
4760 | 100 | |||
4761 | 101 | <set name="OP3" value="Competitor Net"/> | ||
4762 | 102 | <set name="OP3PLMN" value="23403"/> | ||
4763 | 103 | <set name="OP3STATE" value="3"/> | ||
4764 | 104 | |||
4765 | 105 | <set name="OP4" value="Blocked Net"/> | ||
4766 | 106 | <set name="OP4PLMN" value="23404"/> | ||
4767 | 107 | <set name="OP4STATE" value="3"/> | ||
4768 | 108 | |||
4769 | 109 | <set name="OP5" value="Inaccessible Net"/> | ||
4770 | 110 | <set name="OP5PLMN" value="23405"/> | ||
4771 | 111 | <set name="OP5STATE" value="3"/> | ||
4772 | 112 | |||
4773 | 113 | <set name="OP6" value="Phone Net"/> | ||
4774 | 114 | <set name="OP6PLMN" value="23406"/> | ||
4775 | 115 | <set name="OP6STATE" value="1"/> | ||
4776 | 116 | |||
4777 | 117 | <set name="OP7" value="Teleco Net"/> | ||
4778 | 118 | <set name="OP7PLMN" value="24681"/> | ||
4779 | 119 | <set name="OP7STATE" value="1"/> | ||
4780 | 120 | |||
4781 | 121 | <set name="OP8" value="Mobile Net"/> | ||
4782 | 122 | <set name="OP8PLMN" value="24682"/> | ||
4783 | 123 | <set name="OP8STATE" value="1"/> | ||
4784 | 124 | |||
4785 | 125 | <set name="OP9" value="IMSI Unknown"/> | ||
4786 | 126 | <set name="OP9PLMN" value="24683"/> | ||
4787 | 127 | <set name="OP9STATE" value="1"/> | ||
4788 | 128 | |||
4789 | 129 | <set name="OP10" value="NotAllowed"/> | ||
4790 | 130 | <set name="OP10PLMN" value="24684"/> | ||
4791 | 131 | <set name="OP10STATE" value="1"/> | ||
4792 | 132 | |||
4793 | 133 | <set name="OP11" value="NoService"/> | ||
4794 | 134 | <set name="OP11PLMN" value="24685"/> | ||
4795 | 135 | <set name="OP11STATE" value="1"/> | ||
4796 | 136 | |||
4797 | 137 | <!-- Preferred Operators --> | ||
4798 | 138 | <set name="PO1" value="1,2,23401"/> | ||
4799 | 139 | <set name="PO2" value="2,2,23402"/> | ||
4800 | 140 | |||
4801 | 141 | <!-- Name of current mobile phone operator --> | ||
4802 | 142 | <set name="OP" value="${OP1}"/> | ||
4803 | 143 | <set name="OPPLMN" value="${OP1PLMN}"/> | ||
4804 | 144 | |||
4805 | 145 | <!-- Calling line identification presentation flag --> | ||
4806 | 146 | <set name="LIP" value="0"/> | ||
4807 | 147 | |||
4808 | 148 | <!-- Calling line identification restriction flag --> | ||
4809 | 149 | <set name="LIR" value="0"/> | ||
4810 | 150 | <set name="LIR_STATUS" value="3"/> | ||
4811 | 151 | |||
4812 | 152 | <!-- Originating line identification presentation flag --> | ||
4813 | 153 | <set name="OLP" value="0"/> | ||
4814 | 154 | |||
4815 | 155 | <!-- Call waiting presentation mode --> | ||
4816 | 156 | <set name="CWA_V" value="1"/> | ||
4817 | 157 | <set name="CWA_D" value="0"/> | ||
4818 | 158 | <set name="CWA_F" value="0"/> | ||
4819 | 159 | |||
4820 | 160 | <!-- Call forwarding --> | ||
4821 | 161 | <set name="CF0C1" value="0"/> | ||
4822 | 162 | <set name="CF0C2" value="0"/> | ||
4823 | 163 | <set name="CF0C4" value="0"/> | ||
4824 | 164 | <set name="CF0C8" value="0"/> | ||
4825 | 165 | <set name="CF1C1" value="0"/> | ||
4826 | 166 | <set name="CF1C2" value="0"/> | ||
4827 | 167 | <set name="CF1C4" value="0"/> | ||
4828 | 168 | <set name="CF1C8" value="0"/> | ||
4829 | 169 | <set name="CF2C1" value="0"/> | ||
4830 | 170 | <set name="CF2C2" value="0"/> | ||
4831 | 171 | <set name="CF2C4" value="0"/> | ||
4832 | 172 | <set name="CF2C8" value="0"/> | ||
4833 | 173 | <set name="CF3C1" value="0"/> | ||
4834 | 174 | <set name="CF3C2" value="0"/> | ||
4835 | 175 | <set name="CF3C4" value="0"/> | ||
4836 | 176 | <set name="CF3C8" value="0"/> | ||
4837 | 177 | <set name="CF0C1T" value="129"/> | ||
4838 | 178 | <set name="CF1C1T" value="129"/> | ||
4839 | 179 | <set name="CF2C1T" value="129"/> | ||
4840 | 180 | <set name="CF3C1T" value="129"/> | ||
4841 | 181 | <set name="CF2C1O" value="20"/> | ||
4842 | 182 | |||
4843 | 183 | <!-- Service Center Address --> | ||
4844 | 184 | <set name="SCA" value="+15551234567"/> | ||
4845 | 185 | <set name="SCAT" value="145"/> | ||
4846 | 186 | |||
4847 | 187 | <!-- Fixed Dialling presentation mode --> | ||
4848 | 188 | <set name="FD" value="0"/> | ||
4849 | 189 | |||
4850 | 190 | <!-- Unstructured service presentation mode --> | ||
4851 | 191 | <set name="USD" value="0"/> | ||
4852 | 192 | |||
4853 | 193 | <!-- Supplementary service notification flags --> | ||
4854 | 194 | <set name="SSN" value="0,0"/> | ||
4855 | 195 | |||
4856 | 196 | <!-- Phone activity status (ready = 0, ringing = 3, call active = 4) --> | ||
4857 | 197 | <set name="PAS" value="0"/> | ||
4858 | 198 | |||
4859 | 199 | <!-- Phone functionality power consumption level (minimal = 0, full = 1) --> | ||
4860 | 200 | <set name="FUN" value="4"/> | ||
4861 | 201 | |||
4862 | 202 | <!-- Mobile equipment control modes --> | ||
4863 | 203 | <set name="MEC" value="0,0,0"/> | ||
4864 | 204 | |||
4865 | 205 | <!-- Mobile equipment event reporting modes --> | ||
4866 | 206 | <set name="MER" value="0,0,0,0,0"/> | ||
4867 | 207 | |||
4868 | 208 | <!-- Ericsson-style call monitoring status values --> | ||
4869 | 209 | <set name="ECAM" value="0"/> | ||
4870 | 210 | |||
4871 | 211 | <!-- SMS text vs PDU message format (1 = text, 0 = PDU) --> | ||
4872 | 212 | <set name="CMGF" value="0"/> | ||
4873 | 213 | |||
4874 | 214 | <!-- Error reporting mode --> | ||
4875 | 215 | <set name="MEE" value="0"/> | ||
4876 | 216 | |||
4877 | 217 | <!-- SMS message list --> | ||
4878 | 218 | <set name="MSGLIST" value=""/> | ||
4879 | 219 | <set name="MSGLISTCOPY" value=""/> | ||
4880 | 220 | <set name="MSGMEM" value="SM"/> | ||
4881 | 221 | |||
4882 | 222 | <!-- Number of messages in the SMS message list --> | ||
4883 | 223 | <set name="MSGCOUNT" value="0"/> | ||
4884 | 224 | |||
4885 | 225 | <!-- Identifier for the current call --> | ||
4886 | 226 | <set name="CALLID" value="1"/> | ||
4887 | 227 | |||
4888 | 228 | <!-- Name of the PIN that is required (eg. "PIN") --> | ||
4889 | 229 | <!-- READY: PIN/PUK not required; SIM PIN: PIN required; SIM PUK: PUK REQUIRED --> | ||
4890 | 230 | <set name="PINNAME" value="READY"/> | ||
4891 | 231 | |||
4892 | 232 | <!-- Value of the PIN that is required --> | ||
4893 | 233 | <set name="PINVALUE" value="1234"/> | ||
4894 | 234 | |||
4895 | 235 | <!-- How many times can PIN unlocking be attempted --> | ||
4896 | 236 | <set name="PINRETRYCOUNT" value="3"/> | ||
4897 | 237 | |||
4898 | 238 | <!-- pin protection status --> | ||
4899 | 239 | <set name="SC" value="0"/> | ||
4900 | 240 | |||
4901 | 241 | <!-- Value of the PIN2 that is required --> | ||
4902 | 242 | <set name="PIN2VALUE" value="5678"/> | ||
4903 | 243 | |||
4904 | 244 | <!-- Value of the PUK that is required --> | ||
4905 | 245 | <set name="PUKVALUE" value="1234567890"/> | ||
4906 | 246 | |||
4907 | 247 | <!-- Value of the PUK2 that is required --> | ||
4908 | 248 | <set name="PUK2VALUE" value="01010101"/> | ||
4909 | 249 | |||
4910 | 250 | <!-- Value of the PSPIN that is required --> | ||
4911 | 251 | <set name="PSPINVALUE" value="5550"/> | ||
4912 | 252 | |||
4913 | 253 | <!-- phone to sim pin protection status --> | ||
4914 | 254 | <set name="PS" value="0"/> | ||
4915 | 255 | |||
4916 | 256 | <!-- Value of the SIM PIN2 that is required --> | ||
4917 | 257 | <set name="SIMPIN2VALUE" value="666777"/> | ||
4918 | 258 | |||
4919 | 259 | <!-- Call Barring --> | ||
4920 | 260 | <set name="BARVAO" value="0"/> | ||
4921 | 261 | <set name="BARVOI" value="0"/> | ||
4922 | 262 | <set name="BARVOX" value="0"/> | ||
4923 | 263 | <set name="BARVAI" value="0"/> | ||
4924 | 264 | <set name="BARVIR" value="0"/> | ||
4925 | 265 | <set name="BARVNT" value="0"/> | ||
4926 | 266 | <set name="BARVNM" value="0"/> | ||
4927 | 267 | <set name="BARVNS" value="0"/> | ||
4928 | 268 | <set name="BARVNA" value="0"/> | ||
4929 | 269 | <set name="BARVAB" value="0"/> | ||
4930 | 270 | <set name="BARVAG" value="0"/> | ||
4931 | 271 | <set name="BARVAC" value="0"/> | ||
4932 | 272 | |||
4933 | 273 | <!-- accessories, handsfree and car. 0 means not connected, 1 for connected --> | ||
4934 | 274 | <set name="HANDSFREE" value="0"/> | ||
4935 | 275 | |||
4936 | 276 | <set name="CARHANDSFREE" value="0"/> | ||
4937 | 277 | |||
4938 | 278 | <!-- list of available bands --> | ||
4939 | 279 | <set name="BAND0" value="GSM & EGSM"/> | ||
4940 | 280 | <set name="BAND1" value="GSM 1800"/> | ||
4941 | 281 | <set name="BAND2" value="Dualband 900/1800"/> | ||
4942 | 282 | <set name="BAND3" value="PCS 1900"/> | ||
4943 | 283 | <set name="BAND4" value="GSM 850"/> | ||
4944 | 284 | <set name="BAND5" value="Dualband 1900/850"/> | ||
4945 | 285 | <set name="BAND6" value=""/> | ||
4946 | 286 | <set name="BAND7" value=""/> | ||
4947 | 287 | <set name="BAND8" value=""/> | ||
4948 | 288 | <set name="BAND9" value=""/> | ||
4949 | 289 | <set name="BANDA" value=""/> | ||
4950 | 290 | <set name="BANDB" value=""/> | ||
4951 | 291 | <set name="BANDC" value=""/> | ||
4952 | 292 | <set name="BANDD" value=""/> | ||
4953 | 293 | <set name="BANDE" value=""/> | ||
4954 | 294 | <set name="BANDF" value=""/> | ||
4955 | 295 | |||
4956 | 296 | <!-- current band. 0 means automatic and 1,"name" means manually select "name" --> | ||
4957 | 297 | <set name="BAND" value="0"/> | ||
4958 | 298 | |||
4959 | 299 | <!-- Loudspeaker Volume Level --> | ||
4960 | 300 | <set name="LVL" value="125"/> | ||
4961 | 301 | |||
4962 | 302 | <!-- Muting control --> | ||
4963 | 303 | <set name="MUT" value="0"/> | ||
4964 | 304 | |||
4965 | 305 | <!-- CGSMS Bearer control --> | ||
4966 | 306 | <set name="CGSMS" value="3"/> | ||
4967 | 307 | |||
4968 | 308 | <!-- TTY (hearing impared) state --> | ||
4969 | 309 | <set name="PTTY" value="1"/> | ||
4970 | 310 | |||
4971 | 311 | <!-- Positioning reporting state --> | ||
4972 | 312 | <set name="CPOSR" value="0"/> | ||
4973 | 313 | |||
4974 | 314 | <!-- SIM insertion state --> | ||
4975 | 315 | <set name="SIMSTATE" value="1"/> | ||
4976 | 316 | |||
4977 | 317 | <!-- Time --> | ||
4978 | 318 | <!-- Enable for testing | ||
4979 | 319 | <unsolicited delay="3000" once="true">*TTZ: 2, "11/25/2007, 12:12:12+40", 0</unsolicited> | ||
4980 | 320 | <unsolicited delay="3000" once="true">*TTZ: 2, "Cingluar", 0</unsolicited> | ||
4981 | 321 | --> | ||
4982 | 322 | |||
4983 | 323 | <!-- GSM 07.07: General commands --> | ||
4984 | 324 | |||
4985 | 325 | <chat> | ||
4986 | 326 | <!-- Get manufacturer identifier --> | ||
4987 | 327 | <command>AT+CGMI</command> | ||
4988 | 328 | <response>${GMI}\n\nOK</response> | ||
4989 | 329 | </chat> | ||
4990 | 330 | |||
4991 | 331 | <chat> | ||
4992 | 332 | <!-- Get manufacturer identifier support check --> | ||
4993 | 333 | <command>AT+CGMI=?</command> | ||
4994 | 334 | <response>OK</response> | ||
4995 | 335 | </chat> | ||
4996 | 336 | |||
4997 | 337 | <chat> | ||
4998 | 338 | <!-- Get manufacturer identifier, V.25ter version --> | ||
4999 | 339 | <command>AT+GMI</command> | ||
5000 | 340 | <response>${GMI}\n\nOK</response> |