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