Merge lp:~unity-api-team/indicator-network/connectivity-api-mobile-data-management into lp:indicator-network

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: Pete Woods
Approved revision: 596
Merged at revision: 599
Proposed branch: lp:~unity-api-team/indicator-network/connectivity-api-mobile-data-management
Merge into: lp:indicator-network
Prerequisite: lp:~unity-api-team/indicator-network/connectivity-service-mobile-data-management
Diff against target: 1591 lines (+1346/-3)
18 files modified
data/connectivity-qt.map (+20/-0)
debian/changelog (+6/-0)
src/connectivity-api/connectivity-qml/CMakeLists.txt (+1/-1)
src/connectivity-api/connectivity-qml/plugin.cpp (+10/-0)
src/connectivity-api/connectivity-qt/CMakeLists.txt (+18/-0)
src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp (+117/-2)
src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h (+34/-0)
src/connectivity-api/connectivity-qt/connectivityqt/internal/modems-list-model-parameters.h (+45/-0)
src/connectivity-api/connectivity-qt/connectivityqt/internal/sims-list-model-parameters.h (+42/-0)
src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp (+130/-0)
src/connectivity-api/connectivity-qt/connectivityqt/modem.h (+68/-0)
src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp (+192/-0)
src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h (+83/-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 (+235/-0)
src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h (+101/-0)
src/indicator/nmofono/manager-impl.cpp (+1/-0)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/connectivity-api-mobile-data-management
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Needs Fixing
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+293085@code.launchpad.net

Commit message

New Connectivity Service Private API for managing mobile data and SIM cards.

Description of the change

New Connectivity Service Private API for managing mobile data and SIM cards.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
583. By Antti Kaijanmäki

merge.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
584. By Antti Kaijanmäki

fix crash.

585. By Antti Kaijanmäki

merge upstream

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
586. By Antti Kaijanmäki

clean up

587. By Antti Kaijanmäki

merge upstream

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
588. By Antti Kaijanmäki

merge upstream

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
589. By Antti Kaijanmäki

shared pointers everywhere + re-enable symbols map

590. By Antti Kaijanmäki

make simForMobileData shared pointer as well.

591. By Antti Kaijanmäki

hide the constructors of listmodels and move relevant dbus property handling inside the models as well.

592. By Antti Kaijanmäki

restore Connectivity QML to 1.0 import.

Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

no parent pointers to shared_ptr QObject!

review: Needs Fixing
593. By Antti Kaijanmäki

don't set parents to qobjects managed by shared pointers.

594. By Antti Kaijanmäki

revert back to Connectivity 1.0 imports. add missing model parameter headers

Revision history for this message
Pete Woods (pete-woods) wrote :

Use the object owner setter. In your class constructor add (const std::function<void(QObject*)>& objectOwner) as an argument.

stash in a member variable if necessary

m_objectOwner(foo.get())

595. By Pete Woods

Lazy initialization and C++ object ownership

596. By Pete Woods

Add changelog message

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/connectivity-qt.map'
2--- data/connectivity-qt.map 2015-11-20 13:14:50 +0000
3+++ data/connectivity-qt.map 2016-05-26 13:16:24 +0000
4@@ -6,26 +6,46 @@
5 typeinfo*for?connectivityqt::VpnConnection;
6 typeinfo*for?connectivityqt::VpnConnectionsListModel;
7 typeinfo*for?ubuntu::connectivity::NetworkingStatus;
8+ typeinfo*for?connectivityqt::Modem;
9+ typeinfo*for?connectivityqt::ModemsListModel;
10+ typeinfo*for?connectivityqt::Sim;
11+ typeinfo*for?connectivityqt::SimsListModel;
12 VTT?for?connectivityqt::Connectivity;
13 VTT?for?connectivityqt::OpenvpnConnection;
14 VTT?for?connectivityqt::VpnConnection;
15 VTT?for?connectivityqt::VpnConnectionsListModel;
16 VTT?for?ubuntu::connectivity::NetworkingStatus;
17+ VTT?for?connectivityqt::Modem;
18+ VTT?for?connectivityqt::ModemsListModel;
19+ VTT?for?connectivityqt::Sim;
20+ VTT?for?connectivityqt::SimsListModel;
21 virtual?thunk?to?connectivityqt::Connectivity;
22 virtual?thunk?to?connectivityqt::OpenvpnConnection;
23 virtual?thunk?to?connectivityqt::VpnConnection;
24 virtual?thunk?to?connectivityqt::VpnConnectionsListModel;
25 virtual?thunk?to?ubuntu::connectivity::NetworkingStatus;
26+ virtual?thunk?to?connectivityqt::Modem;
27+ virtual?thunk?to?connectivityqt::ModemsListModel;
28+ virtual?thunk?to?connectivityqt::Sim;
29+ virtual?thunk?to?connectivityqt::SimsListModel;
30 vtable?for?connectivityqt::Connectivity;
31 vtable?for?connectivityqt::OpenvpnConnection;
32 vtable?for?connectivityqt::VpnConnection;
33 vtable?for?connectivityqt::VpnConnectionsListModel;
34 vtable?for?ubuntu::connectivity::NetworkingStatus;
35+ vtable?for?connectivityqt::Modem;
36+ vtable?for?connectivityqt::ModemsListModel;
37+ vtable?for?connectivityqt::Sim;
38+ vtable?for?connectivityqt::SimsListModel;
39 connectivityqt::Connectivity::[!P]*;
40 connectivityqt::OpenvpnConnection::[!P]*;
41 connectivityqt::VpnConnection::[!P]*;
42 connectivityqt::VpnConnectionsListModel::[!P]*;
43 ubuntu::connectivity::NetworkingStatus::[!P]*;
44+ connectivityqt::Modem::[!P]*;
45+ connectivityqt::ModemsListModel::[!P]*;
46+ connectivityqt::Sim::[!P]*;
47+ connectivityqt::SimsListModel::[!P]*;
48 };
49 local:
50 *;
51
52=== modified file 'debian/changelog'
53--- debian/changelog 2016-05-11 16:57:40 +0000
54+++ debian/changelog 2016-05-26 13:16:24 +0000
55@@ -1,3 +1,9 @@
56+indicator-network (0.8.0-0ubuntu1) UNRELEASED; urgency=medium
57+
58+ * Add SIM management API.
59+
60+ -- Pete <pete.woods@canonical.com> Thu, 26 May 2016 14:15:03 +0100
61+
62 indicator-network (0.7.1+16.04.20160511-0ubuntu1) xenial; urgency=medium
63
64 [ Pete Woods ]
65
66=== modified file 'src/connectivity-api/connectivity-qml/CMakeLists.txt'
67--- src/connectivity-api/connectivity-qml/CMakeLists.txt 2015-05-19 13:49:21 +0000
68+++ src/connectivity-api/connectivity-qml/CMakeLists.txt 2016-05-26 13:16:24 +0000
69@@ -8,7 +8,7 @@
70 )
71
72 set(CONNECTIVITY_QML_SRC
73- plugin.cpp
74+ plugin.cpp
75 )
76
77 add_library(connectivity-qml SHARED
78
79=== modified file 'src/connectivity-api/connectivity-qml/plugin.cpp'
80--- src/connectivity-api/connectivity-qml/plugin.cpp 2015-12-04 13:18:04 +0000
81+++ src/connectivity-api/connectivity-qml/plugin.cpp 2016-05-26 13:16:24 +0000
82@@ -21,6 +21,12 @@
83 #include <connectivityqt/connectivity.h>
84 #include <connectivityqt/openvpn-connection.h>
85
86+#include <connectivityqt/sim.h>
87+
88+#include <connectivityqt/modems-list-model.h>
89+#include <connectivityqt/sims-list-model.h>
90+
91+
92 #include <QtQml>
93
94 namespace
95@@ -48,6 +54,10 @@
96 qmlRegisterUncreatableType<connectivityqt::VpnConnectionsListModel>(uri, 1, 0, "VpnConnectionsListModel", "Access VpnConnectionsListModel via Connectivity object");
97 qmlRegisterUncreatableType<connectivityqt::VpnConnection>(uri, 1, 0, "VpnConnection", "Access VpnConnection via VpnConnectionsListModel object");
98 qmlRegisterUncreatableType<connectivityqt::OpenvpnConnection>(uri, 1, 0, "OpenvpnConnection", "Access OpenvpnConnection via VpnConnectionsListModel object");
99+
100+ qmlRegisterUncreatableType<connectivityqt::Sim>(uri, 1, 0, "Sim", "");
101+ qmlRegisterUncreatableType<connectivityqt::ModemsListModel>(uri, 1, 0, "ModemsListModel", "");
102+ qmlRegisterUncreatableType<connectivityqt::ModemsListModel>(uri, 1, 0, "SimsListModel", "");
103 }
104
105 void
106
107=== modified file 'src/connectivity-api/connectivity-qt/CMakeLists.txt'
108--- src/connectivity-api/connectivity-qt/CMakeLists.txt 2016-02-17 10:58:27 +0000
109+++ src/connectivity-api/connectivity-qt/CMakeLists.txt 2016-05-26 13:16:24 +0000
110@@ -22,6 +22,10 @@
111 CONNECTIVITY_QT_SRC
112 connectivityqt/internal/dbus-property-cache.cpp
113 connectivityqt/connectivity.cpp
114+ connectivityqt/modem.cpp
115+ connectivityqt/modems-list-model.cpp
116+ connectivityqt/sim.cpp
117+ connectivityqt/sims-list-model.cpp
118 connectivityqt/openvpn-connection.cpp
119 connectivityqt/pptp-connection.cpp
120 connectivityqt/vpn-connection.cpp
121@@ -33,6 +37,8 @@
122 "${DATA_DIR}/org.freedesktop.DBus.Properties.xml"
123 "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml"
124 "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml"
125+ "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml"
126+ "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml"
127 "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml"
128 "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.OpenVpn.xml"
129 "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.Pptp.xml"
130@@ -54,6 +60,18 @@
131
132 qt5_add_dbus_interface(
133 CONNECTIVITY_QT_SRC
134+ "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml"
135+ ModemInterface
136+)
137+
138+qt5_add_dbus_interface(
139+ CONNECTIVITY_QT_SRC
140+ "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml"
141+ SimInterface
142+)
143+
144+qt5_add_dbus_interface(
145+ CONNECTIVITY_QT_SRC
146 "${DATA_DIR}/com.ubuntu.connectivity1.vpn.VpnConnection.xml"
147 VpnConnectionInterface
148 )
149
150=== modified file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp'
151--- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 2015-12-04 13:18:04 +0000
152+++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 2016-05-26 13:16:24 +0000
153@@ -18,8 +18,12 @@
154 */
155
156 #include <connectivityqt/connectivity.h>
157+#include <connectivityqt/internal/sims-list-model-parameters.h>
158+#include <connectivityqt/internal/modems-list-model-parameters.h>
159 #include <connectivityqt/internal/vpn-connection-list-model-parameters.h>
160 #include <connectivityqt/vpn-connections-list-model.h>
161+#include <connectivityqt/modems-list-model.h>
162+#include <connectivityqt/sims-list-model.h>
163 #include <dbus-types.h>
164 #include <NetworkingStatusInterface.h>
165 #include <NetworkingStatusPrivateInterface.h>
166@@ -57,6 +61,11 @@
167
168 VpnConnectionsListModel::SPtr m_vpnConnectionsModel;
169
170+ SimsListModel::SPtr m_simsModel;
171+ ModemsListModel::SPtr m_modemsModel;
172+
173+ Sim::SPtr m_simForMobileData;
174+
175 static QVector<Limitations> toLimitations(const QVariant& value)
176 {
177 auto l = value.toStringList();
178@@ -164,6 +173,23 @@
179 {
180 Q_EMIT p.hotspotStoredUpdated(value.toBool());
181 }
182+ else if (name == "MobileDataEnabled")
183+ {
184+ Q_EMIT p.mobileDataEnabledUpdated(value.toBool());
185+ }
186+ else if (name == "SimForMobileData")
187+ {
188+ auto path = value.value<QDBusObjectPath>();
189+ auto sim = m_simsModel->getSimByPath(path);
190+ p.setSimForMobileData(sim.get());
191+ }
192+ }
193+
194+ void simsUpdated()
195+ {
196+ auto path = m_writePropertyCache->get("SimForMobileData").value<QDBusObjectPath>();
197+ auto sim = m_simsModel->getSimByPath(path);
198+ p.setSimForMobileData(sim.get());
199 }
200
201 };
202@@ -178,6 +204,8 @@
203
204 qRegisterMetaType<connectivityqt::VpnConnection*>("VpnConnection*");
205 qRegisterMetaType<connectivityqt::VpnConnection::Type>("VpnConnection::Type");
206+
207+ qRegisterMetaType<connectivityqt::Sim*>("Sim*");
208 }
209
210 Connectivity::Connectivity(const QDBusConnection& sessionConnection, QObject* parent) :
211@@ -225,14 +253,14 @@
212 &internal::DBusPropertyCache::initialized, d.get(),
213 &Connectivity::Priv::interfaceInitialized);
214
215+
216 connect(d->m_writeInterface.get(),
217 &ComUbuntuConnectivity1PrivateInterface::ReportError, this,
218 &Connectivity::reportError);
219 }
220
221 Connectivity::~Connectivity()
222-{
223-}
224+{}
225
226 bool Connectivity::flightMode() const
227 {
228@@ -384,6 +412,93 @@
229 return d->m_vpnConnectionsModel.get();
230 }
231
232+bool Connectivity::mobileDataEnabled() const
233+{
234+ return d->m_writePropertyCache->get("MobileDataEnabled").toBool();
235+}
236+
237+void Connectivity::setMobileDataEnabled(bool enabled)
238+{
239+ d->m_writeInterface->setMobileDataEnabled(enabled);
240+}
241+
242+Sim *Connectivity::simForMobileData() const
243+{
244+ return d->m_simForMobileData.get();
245+}
246+
247+void Connectivity::setSimForMobileData(Sim *sim_raw)
248+{
249+ Sim::SPtr sim;
250+ if (sim_raw)
251+ {
252+ sim = sim_raw->shared_from_this();
253+ }
254+
255+ if (d->m_simForMobileData == sim)
256+ {
257+ return;
258+ }
259+ d->m_simForMobileData = sim;
260+ QDBusObjectPath path;
261+ if (sim)
262+ {
263+ path = sim->path();
264+ }
265+ else
266+ {
267+ path = QDBusObjectPath("/");
268+ }
269+ if (d->m_writePropertyCache->get("SimForMobileData").value<QDBusObjectPath>() != path)
270+ {
271+ d->m_writeInterface->setSimForMobileData(path);
272+ }
273+ Q_EMIT simForMobileDataUpdated(sim.get());
274+}
275+
276+QAbstractItemModel* Connectivity::modems() const
277+{
278+ // Lazy initialisation
279+ if (!d->m_modemsModel)
280+ {
281+ // We call this to ensure the SIMs model has been created.
282+ sims();
283+ d->m_modemsModel = std::make_shared<ModemsListModel>(
284+ internal::ModemsListModelParameters{
285+ d->m_objectOwner,
286+ d->m_writeInterface,
287+ d->m_writePropertyCache,
288+ d->m_simsModel});
289+ d->m_objectOwner(d->m_modemsModel.get());
290+ }
291+
292+ return d->m_modemsModel.get();
293+}
294+
295+QAbstractItemModel *Connectivity::sims() const
296+{
297+ // Lazy initialisation
298+ if (!d->m_simsModel)
299+ {
300+ d->m_simsModel = std::make_shared<SimsListModel>(
301+ internal::SimsListModelParameters{
302+ d->m_objectOwner,
303+ d->m_writeInterface,
304+ d->m_writePropertyCache});
305+ d->m_objectOwner(d->m_simsModel.get());
306+
307+ connect(d->m_simsModel.get(), &SimsListModel::simsUpdated, d.get(), &Priv::simsUpdated);
308+
309+ if (d->m_writePropertyCache->isInitialized()) {
310+ auto sim = d->m_simsModel->getSimByPath(d->m_writePropertyCache->get("SimForMobileData").value<QDBusObjectPath>());
311+ d->m_simForMobileData = sim;
312+ }
313+ }
314+
315+ return d->m_simsModel.get();
316+}
317+
318+
319 }
320
321 #include "connectivity.moc"
322
323=== modified file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h'
324--- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 2016-05-10 09:50:41 +0000
325+++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 2016-05-26 13:16:24 +0000
326@@ -30,9 +30,13 @@
327
328 #include <connectivityqt/vpn-connections-list-model.h>
329
330+#include <QDBusObjectPath>
331+
332 namespace connectivityqt
333 {
334
335+class Sim;
336+
337 class Q_DECL_EXPORT Connectivity: public QObject
338 {
339 Q_OBJECT
340@@ -138,6 +142,28 @@
341 Q_PROPERTY(QAbstractItemModel* vpnConnections READ vpnConnections NOTIFY vpnConnectionsUpdated)
342 QAbstractItemModel* vpnConnections() const;
343
344+ Q_PROPERTY(bool mobileDataEnabled
345+ READ mobileDataEnabled
346+ WRITE setMobileDataEnabled
347+ NOTIFY mobileDataEnabledUpdated)
348+ bool mobileDataEnabled() const;
349+
350+ Q_PROPERTY(Sim* simForMobileData
351+ READ simForMobileData
352+ WRITE setSimForMobileData
353+ NOTIFY simForMobileDataUpdated)
354+ Sim* simForMobileData() const;
355+
356+ Q_PROPERTY(QAbstractItemModel* modems
357+ READ modems
358+ CONSTANT)
359+ QAbstractItemModel* modems() const;
360+
361+ Q_PROPERTY(QAbstractItemModel* sims
362+ READ sims
363+ CONSTANT)
364+ QAbstractItemModel* sims() const;
365+
366 public Q_SLOTS:
367 void setFlightMode(bool enabled);
368
369@@ -153,6 +179,10 @@
370
371 void setHotspotAuth(const QString& auth);
372
373+ void setMobileDataEnabled(bool enabled);
374+
375+ void setSimForMobileData(Sim *sim);
376+
377 Q_SIGNALS:
378 void flightModeUpdated(bool);
379
380@@ -194,6 +224,10 @@
381
382 void vpnConnectionsUpdated(QAbstractItemModel*);
383
384+ void mobileDataEnabledUpdated(bool);
385+
386+ void simForMobileDataUpdated(Sim* sim);
387+
388 protected:
389 class Priv;
390 std::shared_ptr<Priv> d;
391
392=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/internal/modems-list-model-parameters.h'
393--- src/connectivity-api/connectivity-qt/connectivityqt/internal/modems-list-model-parameters.h 1970-01-01 00:00:00 +0000
394+++ src/connectivity-api/connectivity-qt/connectivityqt/internal/modems-list-model-parameters.h 2016-05-26 13:16:24 +0000
395@@ -0,0 +1,45 @@
396+/*
397+ * Copyright © 2016 Canonical Ltd.
398+ *
399+ * This program is free software: you can redistribute it and/or modify it
400+ * under the terms of the GNU Lesser General Public License version 3,
401+ * as published by the Free Software Foundation.
402+ *
403+ * This program is distributed in the hope that it will be useful,
404+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
405+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
406+ * GNU Lesser General Public License for more details.
407+ *
408+ * You should have received a copy of the GNU Lesser General Public License
409+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
410+ *
411+ * Authors:
412+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
413+ */
414+
415+#pragma once
416+
417+#include <connectivityqt/internal/dbus-property-cache.h>
418+
419+#include <NetworkingStatusPrivateInterface.h>
420+
421+#include <connectivityqt/sims-list-model.h>
422+
423+#include <functional>
424+#include <memory>
425+
426+namespace connectivityqt
427+{
428+namespace internal
429+{
430+
431+struct ModemsListModelParameters
432+{
433+ std::function<void(QObject*)> objectOwner;
434+ std::shared_ptr<ComUbuntuConnectivity1PrivateInterface> writeInterface;
435+ std::shared_ptr<internal::DBusPropertyCache> propertyCache;
436+ SimsListModel::SPtr sims;
437+};
438+
439+}
440+}
441
442=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/internal/sims-list-model-parameters.h'
443--- src/connectivity-api/connectivity-qt/connectivityqt/internal/sims-list-model-parameters.h 1970-01-01 00:00:00 +0000
444+++ src/connectivity-api/connectivity-qt/connectivityqt/internal/sims-list-model-parameters.h 2016-05-26 13:16:24 +0000
445@@ -0,0 +1,42 @@
446+/*
447+ * Copyright © 2016 Canonical Ltd.
448+ *
449+ * This program is free software: you can redistribute it and/or modify it
450+ * under the terms of the GNU Lesser General Public License version 3,
451+ * as published by the Free Software Foundation.
452+ *
453+ * This program is distributed in the hope that it will be useful,
454+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
455+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
456+ * GNU Lesser General Public License for more details.
457+ *
458+ * You should have received a copy of the GNU Lesser General Public License
459+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
460+ *
461+ * Authors:
462+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
463+ */
464+
465+#pragma once
466+
467+#include <connectivityqt/internal/dbus-property-cache.h>
468+
469+#include <NetworkingStatusPrivateInterface.h>
470+
471+#include <functional>
472+#include <memory>
473+
474+namespace connectivityqt
475+{
476+namespace internal
477+{
478+
479+struct SimsListModelParameters
480+{
481+ std::function<void(QObject*)> objectOwner;
482+ std::shared_ptr<ComUbuntuConnectivity1PrivateInterface> writeInterface;
483+ std::shared_ptr<internal::DBusPropertyCache> propertyCache;
484+};
485+
486+}
487+}
488
489=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp'
490--- src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp 1970-01-01 00:00:00 +0000
491+++ src/connectivity-api/connectivity-qt/connectivityqt/modem.cpp 2016-05-26 13:16:24 +0000
492@@ -0,0 +1,130 @@
493+/*
494+ * Copyright © 2016 Canonical Ltd.
495+ *
496+ * This program is free software: you can redistribute it and/or modify it
497+ * under the terms of the GNU Lesser General Public License version 3,
498+ * as published by the Free Software Foundation.
499+ *
500+ * This program is distributed in the hope that it will be useful,
501+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
502+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503+ * GNU Lesser General Public License for more details.
504+ *
505+ * You should have received a copy of the GNU Lesser General Public License
506+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
507+ *
508+ * Authors:
509+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
510+ */
511+
512+#include <connectivityqt/internal/dbus-property-cache.h>
513+#include <connectivityqt/modem.h>
514+#include <dbus-types.h>
515+
516+#include <ModemInterface.h>
517+
518+using namespace std;
519+
520+namespace connectivityqt
521+{
522+
523+class Modem::Priv: public QObject
524+{
525+ Q_OBJECT
526+
527+public:
528+ Priv(Modem& parent) :
529+ p(parent)
530+ {
531+ }
532+
533+public Q_SLOTS:
534+ void propertyChanged(const QString& name, const QVariant& value)
535+ {
536+ if (name == "Sim")
537+ {
538+ auto sim = m_sims->getSimByPath(value.value<QDBusObjectPath>());
539+ setSim(sim);
540+ }
541+ }
542+
543+ void simsUpdated()
544+ {
545+ auto sim = m_sims->getSimByPath(m_propertyCache->get("Sim").value<QDBusObjectPath>());
546+ setSim(sim);
547+ }
548+
549+ void setSim(Sim::SPtr sim)
550+ {
551+ if (m_sim == sim)
552+ {
553+ return;
554+ }
555+ m_sim = sim;
556+ Q_EMIT p.simChanged(m_sim.get());
557+ }
558+
559+public:
560+ Modem& p;
561+
562+ Sim::SPtr m_sim;
563+ SimsListModel::SPtr m_sims;
564+
565+ unique_ptr<ComUbuntuConnectivity1ModemInterface> m_modemInterface;
566+
567+ internal::DBusPropertyCache::UPtr m_propertyCache;
568+};
569+
570+Modem::Modem(const QDBusObjectPath& path,
571+ const QDBusConnection& connection,
572+ SimsListModel::SPtr sims,
573+ QObject* parent) :
574+ QObject(parent), d(new Priv(*this))
575+{
576+ d->m_sims = sims;
577+ d->m_modemInterface = make_unique<
578+ ComUbuntuConnectivity1ModemInterface>(
579+ DBusTypes::DBUS_NAME, path.path(), connection);
580+
581+ d->m_propertyCache =
582+ make_unique<internal::DBusPropertyCache>(
583+ DBusTypes::DBUS_NAME,
584+ ComUbuntuConnectivity1ModemInterface::staticInterfaceName(),
585+ path.path(), connection);
586+
587+ connect(d->m_propertyCache.get(),
588+ &internal::DBusPropertyCache::propertyChanged, d.get(),
589+ &Priv::propertyChanged);
590+
591+ d->m_sim = d->m_sims->getSimByPath(d->m_propertyCache->get("Sim").value<QDBusObjectPath>());
592+
593+ connect(d->m_sims.get(), &SimsListModel::simsUpdated, d.get(), &Priv::simsUpdated);
594+}
595+
596+Modem::~Modem()
597+{
598+}
599+
600+QDBusObjectPath Modem::path() const
601+{
602+ return QDBusObjectPath(d->m_modemInterface->path());
603+}
604+
605+int Modem::index() const
606+{
607+ return d->m_propertyCache->get("Index").toInt();
608+}
609+
610+Sim *Modem::sim() const
611+{
612+ return d->m_sim.get();
613+}
614+
615+QString Modem::serial() const
616+{
617+ return d->m_propertyCache->get("Serial").toString();
618+}
619+
620+}
621+
622+#include "modem.moc"
623
624=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/modem.h'
625--- src/connectivity-api/connectivity-qt/connectivityqt/modem.h 1970-01-01 00:00:00 +0000
626+++ src/connectivity-api/connectivity-qt/connectivityqt/modem.h 2016-05-26 13:16:24 +0000
627@@ -0,0 +1,68 @@
628+/*
629+ * Copyright © 2016 Canonical Ltd.
630+ *
631+ * This program is free software: you can redistribute it and/or modify it
632+ * under the terms of the GNU Lesser General Public License version 3,
633+ * as published by the Free Software Foundation.
634+ *
635+ * This program is distributed in the hope that it will be useful,
636+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
637+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
638+ * GNU Lesser General Public License for more details.
639+ *
640+ * You should have received a copy of the GNU Lesser General Public License
641+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
642+ *
643+ * Authors:
644+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
645+ */
646+
647+#pragma once
648+
649+#include <QDBusConnection>
650+#include <QDBusObjectPath>
651+#include <QObject>
652+
653+#include <unity/util/DefinesPtrs.h>
654+#include <connectivityqt/sims-list-model.h>
655+
656+namespace connectivityqt
657+{
658+
659+class Q_DECL_EXPORT Modem : public QObject
660+{
661+ Q_OBJECT
662+
663+public:
664+ UNITY_DEFINES_PTRS(Modem);
665+
666+ Modem(const QDBusObjectPath& path,
667+ const QDBusConnection& connection,
668+ SimsListModel::SPtr sims,
669+ QObject* parent = 0);
670+
671+ virtual ~Modem();
672+
673+ Q_PROPERTY(QDBusObjectPath path READ path)
674+ QDBusObjectPath path() const;
675+
676+ Q_PROPERTY(QString serial READ serial)
677+ QString serial() const;
678+
679+ Q_PROPERTY(int index READ index CONSTANT)
680+ int index() const;
681+
682+ Q_PROPERTY(connectivityqt::Sim* sim READ sim NOTIFY simChanged)
683+ Sim* sim() const;
684+
685+public Q_SLOTS:
686+
687+Q_SIGNALS:
688+ void simChanged(Sim *sim);
689+
690+protected:
691+ class Priv;
692+ std::shared_ptr<Priv> d;
693+};
694+
695+}
696
697=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp'
698--- src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp 1970-01-01 00:00:00 +0000
699+++ src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.cpp 2016-05-26 13:16:24 +0000
700@@ -0,0 +1,192 @@
701+/*
702+ * Copyright © 2016 Canonical Ltd.
703+ *
704+ * This program is free software: you can redistribute it and/or modify it
705+ * under the terms of the GNU Lesser General Public License version 3,
706+ * as published by the Free Software Foundation.
707+ *
708+ * This program is distributed in the hope that it will be useful,
709+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
710+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
711+ * GNU Lesser General Public License for more details.
712+ *
713+ * You should have received a copy of the GNU Lesser General Public License
714+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
715+ *
716+ * Authors:
717+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
718+ */
719+
720+#include <connectivityqt/modems-list-model.h>
721+#include <connectivityqt/modem.h>
722+
723+#include "internal/modems-list-model-parameters.h"
724+
725+#include <QDebug>
726+
727+using namespace std;
728+
729+namespace connectivityqt
730+{
731+
732+class ModemsListModel::Priv: public QObject
733+{
734+ Q_OBJECT
735+
736+public:
737+ Priv(ModemsListModel& parent) :
738+ p(parent)
739+ {
740+ }
741+
742+ void updateModemDBusPaths(QList<QDBusObjectPath> values)
743+ {
744+ auto paths = values.toSet();
745+
746+ QSet<QDBusObjectPath> current;
747+ for (const auto& m: m_modems)
748+ {
749+ current << m->path();
750+ }
751+
752+ auto toRemove(current);
753+ toRemove.subtract(paths);
754+
755+ auto toAdd(paths);
756+ toAdd.subtract(current);
757+
758+ QMutableListIterator<Modem::SPtr> i(m_modems);
759+ int idx = 0;
760+ while (i.hasNext())
761+ {
762+ auto modem(i.next());
763+ if (toRemove.contains(modem->path()))
764+ {
765+ p.beginRemoveRows(QModelIndex(), idx, idx);
766+ i.remove();
767+ p.endRemoveRows();
768+ }
769+ else
770+ {
771+ ++idx;
772+ }
773+ }
774+
775+ if (!toAdd.isEmpty())
776+ {
777+ p.beginInsertRows(QModelIndex(), m_modems.size(), m_modems.size() + toAdd.size() - 1);
778+ for (const auto& path: toAdd)
779+ {
780+ auto modem = std::make_shared<Modem>(path, m_propertyCache->connection(), m_sims, nullptr);
781+ m_objectOwner(modem.get());
782+ m_modems << modem;
783+ connect(modem.get(), &Modem::simChanged, this, &Priv::simChanged);
784+ }
785+ p.endInsertRows();
786+ }
787+ }
788+
789+ QModelIndex findModem(QObject* o)
790+ {
791+ auto modem = qobject_cast<Modem*>(o);
792+ for (auto i = m_modems.constBegin(); i != m_modems.constEnd(); ++i)
793+ {
794+ if (i->get() == modem)
795+ {
796+ return p.index(std::distance(m_modems.constBegin(), i));
797+ }
798+ }
799+ return QModelIndex();
800+ }
801+
802+public Q_SLOTS:
803+ void simChanged(Sim *sim)
804+ {
805+ Q_UNUSED(sim)
806+ auto idx = findModem(sender());
807+ p.dataChanged(idx, idx, {ModemsListModel::Roles::RoleSim});
808+ }
809+
810+ void propertyChanged(const QString& name, const QVariant& value)
811+ {
812+ if (name == "Modems")
813+ {
814+ QList<QDBusObjectPath> tmp;
815+ qvariant_cast<QDBusArgument>(value) >> tmp;
816+ updateModemDBusPaths(tmp);
817+ }
818+ }
819+
820+public:
821+ ModemsListModel& p;
822+ function<void(QObject*)> m_objectOwner;
823+ SimsListModel::SPtr m_sims;
824+ QList<QDBusObjectPath> m_dbus_paths;
825+ QList<Modem::SPtr> m_modems;
826+
827+ shared_ptr<ComUbuntuConnectivity1PrivateInterface> m_writeInterface;
828+ internal::DBusPropertyCache::SPtr m_propertyCache;
829+};
830+
831+ModemsListModel::ModemsListModel(const internal::ModemsListModelParameters &parameters) :
832+ QAbstractListModel(0),
833+ d(new Priv(*this))
834+{
835+ d->m_objectOwner = parameters.objectOwner;
836+ d->m_sims = parameters.sims;
837+ d->m_writeInterface = parameters.writeInterface;
838+ d->m_propertyCache = parameters.propertyCache;
839+
840+ connect(d->m_propertyCache.get(),
841+ &internal::DBusPropertyCache::propertyChanged, d.get(),
842+ &Priv::propertyChanged);
843+
844+ QList<QDBusObjectPath> tmp;
845+ qvariant_cast<QDBusArgument>(d->m_propertyCache->get("Modems")) >> tmp;
846+ d->updateModemDBusPaths(tmp);
847+}
848+
849+ModemsListModel::~ModemsListModel()
850+{
851+}
852+
853+int ModemsListModel::columnCount(const QModelIndex &) const
854+{
855+ return 1;
856+}
857+
858+int ModemsListModel::rowCount(const QModelIndex &) const
859+{
860+ return d->m_modems.size();
861+}
862+
863+QVariant ModemsListModel::data(const QModelIndex &index, int role) const
864+{
865+ int row(index.row());
866+ if (row < 0 || row >= d->m_modems.size())
867+ {
868+ return QVariant();
869+ }
870+
871+ auto modem = d->m_modems.value(row);
872+
873+ switch (role)
874+ {
875+ case Roles::RoleIndex:
876+ return modem->index();
877+ break;
878+ case Roles::RoleSerial:
879+ return modem->serial();
880+ break;
881+ case Roles::RoleSim:
882+ return QVariant::fromValue<Sim*>(modem->sim());
883+ break;
884+ }
885+
886+ return QVariant();
887+}
888+
889+
890+}
891+
892+#include "modems-list-model.moc"
893
894=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h'
895--- src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h 1970-01-01 00:00:00 +0000
896+++ src/connectivity-api/connectivity-qt/connectivityqt/modems-list-model.h 2016-05-26 13:16:24 +0000
897@@ -0,0 +1,83 @@
898+/*
899+ * Copyright © 2016 Canonical Ltd.
900+ *
901+ * This program is free software: you can redistribute it and/or modify it
902+ * under the terms of the GNU Lesser General Public License version 3,
903+ * as published by the Free Software Foundation.
904+ *
905+ * This program is distributed in the hope that it will be useful,
906+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
907+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
908+ * GNU Lesser General Public License for more details.
909+ *
910+ * You should have received a copy of the GNU Lesser General Public License
911+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
912+ *
913+ * Authors:
914+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
915+ */
916+
917+#pragma once
918+
919+#include <QAbstractItemModel>
920+#include <QDBusConnection>
921+#include <QDBusObjectPath>
922+
923+#include "sims-list-model.h"
924+
925+#include <unity/util/DefinesPtrs.h>
926+
927+#include <memory>
928+
929+namespace connectivityqt
930+{
931+namespace internal
932+{
933+struct ModemsListModelParameters;
934+}
935+
936+class Q_DECL_EXPORT ModemsListModel : public QAbstractListModel
937+{
938+ Q_OBJECT
939+
940+ Q_ENUMS(Roles)
941+
942+public:
943+ UNITY_DEFINES_PTRS(ModemsListModel);
944+
945+ enum Roles
946+ {
947+ RoleIndex = Qt::UserRole + 1,
948+ RoleSerial,
949+ RoleSim
950+ };
951+
952+ ModemsListModel(const internal::ModemsListModelParameters& parameters);
953+
954+ ~ModemsListModel();
955+
956+ int columnCount(const QModelIndex &parent) const override;
957+
958+ int rowCount(const QModelIndex &parent) const override;
959+
960+ QVariant data(const QModelIndex &index, int role) const override;
961+
962+ QHash<int, QByteArray> roleNames() const override
963+ {
964+ QHash<int, QByteArray> roles;
965+ roles[RoleIndex] = "Index";
966+ roles[RoleSerial] = "Serial";
967+ roles[RoleSim] = "Sim";
968+ return roles;
969+ }
970+
971+public Q_SLOTS:
972+
973+Q_SIGNALS:
974+
975+protected:
976+ class Priv;
977+ std::shared_ptr<Priv> d;
978+};
979+
980+}
981
982=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp'
983--- src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp 1970-01-01 00:00:00 +0000
984+++ src/connectivity-api/connectivity-qt/connectivityqt/sim.cpp 2016-05-26 13:16:24 +0000
985@@ -0,0 +1,153 @@
986+/*
987+ * Copyright © 2016 Canonical Ltd.
988+ *
989+ * This program is free software: you can redistribute it and/or modify it
990+ * under the terms of the GNU Lesser General Public License version 3,
991+ * as published by the Free Software Foundation.
992+ *
993+ * This program is distributed in the hope that it will be useful,
994+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
995+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
996+ * GNU Lesser General Public License for more details.
997+ *
998+ * You should have received a copy of the GNU Lesser General Public License
999+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1000+ *
1001+ * Authors:
1002+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
1003+ */
1004+
1005+#include <connectivityqt/internal/dbus-property-cache.h>
1006+#include <connectivityqt/sim.h>
1007+#include <dbus-types.h>
1008+
1009+#include <SimInterface.h>
1010+
1011+using namespace std;
1012+
1013+namespace connectivityqt
1014+{
1015+
1016+class Sim::Priv: public QObject
1017+{
1018+ Q_OBJECT
1019+
1020+public:
1021+ Priv(Sim& parent) :
1022+ p(parent)
1023+ {
1024+ }
1025+
1026+public Q_SLOTS:
1027+ void propertyChanged(const QString& name, const QVariant& value)
1028+ {
1029+ if (name == "Locked")
1030+ {
1031+ Q_EMIT p.lockedChanged(value.toBool());
1032+ } else if (name == "Present")
1033+ {
1034+ Q_EMIT p.presentChanged(value.toBool());
1035+ } else if (name == "DataRoamingEnabled")
1036+ {
1037+ Q_EMIT p.dataRoamingEnabledChanged(value.toBool());
1038+ } else {
1039+ qWarning() << "connectivityqt::Sim::Priv::propertyChanged(): "
1040+ << "Unexpected property: " << name;
1041+ }
1042+
1043+ }
1044+
1045+public:
1046+ Sim& p;
1047+
1048+ unique_ptr<ComUbuntuConnectivity1SimInterface> m_simInterface;
1049+
1050+ internal::DBusPropertyCache::UPtr m_propertyCache;
1051+};
1052+
1053+Sim::Sim(const QDBusObjectPath& path, const QDBusConnection& connection, QObject* parent) :
1054+ QObject(parent), d(new Priv(*this))
1055+{
1056+ d->m_simInterface = make_unique<
1057+ ComUbuntuConnectivity1SimInterface>(
1058+ DBusTypes::DBUS_NAME, path.path(), connection);
1059+
1060+ d->m_propertyCache =
1061+ make_unique<internal::DBusPropertyCache>(
1062+ DBusTypes::DBUS_NAME,
1063+ ComUbuntuConnectivity1SimInterface::staticInterfaceName(),
1064+ path.path(), connection);
1065+
1066+ connect(d->m_propertyCache.get(),
1067+ &internal::DBusPropertyCache::propertyChanged, d.get(),
1068+ &Priv::propertyChanged);
1069+}
1070+
1071+Sim::~Sim()
1072+{
1073+}
1074+
1075+QDBusObjectPath Sim::path() const
1076+{
1077+ return QDBusObjectPath(d->m_simInterface->path());
1078+}
1079+
1080+QString Sim::imsi() const
1081+{
1082+ return d->m_propertyCache->get("Imsi").toString();
1083+}
1084+
1085+QString Sim::primaryPhoneNumber() const
1086+{
1087+ return d->m_propertyCache->get("PrimaryPhoneNumber").toString();
1088+}
1089+
1090+QList<QString> Sim::phoneNumbers() const
1091+{
1092+ return d->m_propertyCache->get("PhoneNumbers").toStringList();
1093+}
1094+
1095+bool Sim::locked() const
1096+{
1097+ return d->m_propertyCache->get("Locked").toBool();
1098+}
1099+
1100+bool Sim::present() const
1101+{
1102+ return d->m_propertyCache->get("Present").toBool();
1103+}
1104+
1105+QString Sim::mcc() const
1106+{
1107+ return d->m_propertyCache->get("Mcc").toString();
1108+}
1109+
1110+QString Sim::mnc() const
1111+{
1112+ return d->m_propertyCache->get("Mnc").toString();
1113+}
1114+
1115+QList<QString> Sim::preferredLanguages() const
1116+{
1117+ return d->m_propertyCache->get("PreferredLanguages").toStringList();
1118+}
1119+
1120+bool Sim::dataRoamingEnabled() const
1121+{
1122+ return d->m_propertyCache->get("DataRoamingEnabled").toBool();
1123+}
1124+
1125+void Sim::setDataRoamingEnabled(bool value)
1126+{
1127+ d->m_propertyCache->set("DataRoamingEnabled", QVariant(value));
1128+}
1129+
1130+void Sim::unlock()
1131+{
1132+ d->m_simInterface->Unlock();
1133+}
1134+
1135+}
1136+
1137+#include "sim.moc"
1138+
1139
1140=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/sim.h'
1141--- src/connectivity-api/connectivity-qt/connectivityqt/sim.h 1970-01-01 00:00:00 +0000
1142+++ src/connectivity-api/connectivity-qt/connectivityqt/sim.h 2016-05-26 13:16:24 +0000
1143@@ -0,0 +1,90 @@
1144+/*
1145+ * Copyright © 2016 Canonical Ltd.
1146+ *
1147+ * This program is free software: you can redistribute it and/or modify it
1148+ * under the terms of the GNU Lesser General Public License version 3,
1149+ * as published by the Free Software Foundation.
1150+ *
1151+ * This program is distributed in the hope that it will be useful,
1152+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1153+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1154+ * GNU Lesser General Public License for more details.
1155+ *
1156+ * You should have received a copy of the GNU Lesser General Public License
1157+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1158+ *
1159+ * Authors:
1160+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
1161+ */
1162+
1163+#pragma once
1164+
1165+#include <QDBusConnection>
1166+#include <QDBusObjectPath>
1167+#include <QObject>
1168+
1169+#include <unity/util/DefinesPtrs.h>
1170+
1171+namespace connectivityqt
1172+{
1173+
1174+class Q_DECL_EXPORT Sim : public QObject, public std::enable_shared_from_this<Sim>
1175+{
1176+ Q_OBJECT
1177+
1178+public:
1179+ UNITY_DEFINES_PTRS(Sim);
1180+
1181+ Sim(const QDBusObjectPath& path, const QDBusConnection& connection, QObject* parent = 0);
1182+
1183+ virtual ~Sim();
1184+
1185+ Q_PROPERTY(QDBusObjectPath path READ path)
1186+ QDBusObjectPath path() const;
1187+
1188+ Q_PROPERTY(QString Imsi READ imsi CONSTANT)
1189+ QString imsi() const;
1190+
1191+ Q_PROPERTY(QString PrimaryPhoneNumber READ primaryPhoneNumber CONSTANT)
1192+ QString primaryPhoneNumber() const;
1193+
1194+ Q_PROPERTY(QList<QString> PhoneNumbers READ phoneNumbers CONSTANT)
1195+ QList<QString> phoneNumbers() const;
1196+
1197+ Q_PROPERTY(bool Locked READ locked NOTIFY lockedChanged)
1198+ bool locked() const;
1199+
1200+ Q_PROPERTY(bool Present READ present NOTIFY presentChanged)
1201+ bool present() const;
1202+
1203+ Q_PROPERTY(QString Mcc READ mcc CONSTANT)
1204+ QString mcc() const;
1205+
1206+ Q_PROPERTY(QString Mnc READ mnc CONSTANT)
1207+ QString mnc() const;
1208+
1209+ Q_PROPERTY(QList<QString> PreferredLanguages READ preferredLanguages CONSTANT)
1210+ QList<QString> preferredLanguages() const;
1211+
1212+ Q_PROPERTY(bool DataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled NOTIFY dataRoamingEnabledChanged)
1213+ bool dataRoamingEnabled() const;
1214+ void setDataRoamingEnabled(bool value);
1215+
1216+public Q_SLOTS:
1217+
1218+ void unlock();
1219+
1220+Q_SIGNALS:
1221+ void lockedChanged(bool value);
1222+ void presentChanged(bool value);
1223+ void dataRoamingEnabledChanged(bool value);
1224+
1225+
1226+protected:
1227+ class Priv;
1228+ std::shared_ptr<Priv> d;
1229+};
1230+
1231+}
1232+
1233+Q_DECLARE_METATYPE(connectivityqt::Sim*)
1234
1235=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp'
1236--- src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp 1970-01-01 00:00:00 +0000
1237+++ src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.cpp 2016-05-26 13:16:24 +0000
1238@@ -0,0 +1,235 @@
1239+/*
1240+ * Copyright © 2016 Canonical Ltd.
1241+ *
1242+ * This program is free software: you can redistribute it and/or modify it
1243+ * under the terms of the GNU Lesser General Public License version 3,
1244+ * as published by the Free Software Foundation.
1245+ *
1246+ * This program is distributed in the hope that it will be useful,
1247+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1248+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1249+ * GNU Lesser General Public License for more details.
1250+ *
1251+ * You should have received a copy of the GNU Lesser General Public License
1252+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1253+ *
1254+ * Authors:
1255+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
1256+ */
1257+
1258+#include <connectivityqt/sims-list-model.h>
1259+
1260+#include "internal/sims-list-model-parameters.h"
1261+
1262+#include <QDebug>
1263+
1264+using namespace std;
1265+
1266+namespace connectivityqt
1267+{
1268+
1269+class SimsListModel::Priv: public QObject
1270+{
1271+ Q_OBJECT
1272+
1273+public:
1274+ Priv(SimsListModel& parent) :
1275+ p(parent)
1276+ {
1277+ }
1278+
1279+ void updateSimDBusPaths(QList<QDBusObjectPath> values)
1280+ {
1281+ auto paths = values.toSet();
1282+
1283+ QSet<QDBusObjectPath> current;
1284+ for (const auto& m: m_sims)
1285+ {
1286+ current << m->path();
1287+ }
1288+
1289+ auto toRemove(current);
1290+ toRemove.subtract(paths);
1291+
1292+ auto toAdd(paths);
1293+ toAdd.subtract(current);
1294+
1295+ QMutableListIterator<Sim::SPtr> i(m_sims);
1296+ int idx = 0;
1297+ while (i.hasNext())
1298+ {
1299+ auto sim(i.next());
1300+ if (toRemove.contains(sim->path()))
1301+ {
1302+ p.beginRemoveRows(QModelIndex(), idx, idx);
1303+ i.remove();
1304+ p.endRemoveRows();
1305+ }
1306+ else
1307+ {
1308+ ++idx;
1309+ }
1310+ }
1311+
1312+ if (!toAdd.isEmpty())
1313+ {
1314+ p.beginInsertRows(QModelIndex(), m_sims.size(), m_sims.size() + toAdd.size() - 1);
1315+ for (const auto& path: toAdd)
1316+ {
1317+ auto sim = std::make_shared<Sim>(path, m_propertyCache->connection(), nullptr);
1318+ m_objectOwner(sim.get());
1319+ m_sims << sim;
1320+ connect(sim.get(), &Sim::lockedChanged, this, &Priv::lockedChanged);
1321+ connect(sim.get(), &Sim::presentChanged, this, &Priv::presentChanged);
1322+ connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Priv::dataRoamingEnabledChanged);
1323+ }
1324+ p.endInsertRows();
1325+ }
1326+
1327+ Q_EMIT p.simsUpdated();
1328+ }
1329+
1330+ QModelIndex findSim(QObject* o)
1331+ {
1332+ auto sim = qobject_cast<Sim*>(o);
1333+ for (auto i = m_sims.constBegin(); i != m_sims.constEnd(); ++i)
1334+ {
1335+ if (i->get() == sim)
1336+ {
1337+ return p.index(std::distance(m_sims.constBegin(), i));
1338+ }
1339+ }
1340+ return QModelIndex();
1341+ }
1342+
1343+public Q_SLOTS:
1344+ void lockedChanged()
1345+ {
1346+ auto idx = findSim(sender());
1347+ p.dataChanged(idx, idx, {SimsListModel::Roles::RoleLocked});
1348+ }
1349+
1350+ void presentChanged()
1351+ {
1352+ auto idx = findSim(sender());
1353+ p.dataChanged(idx, idx, {SimsListModel::Roles::RolePresent});
1354+ }
1355+ void dataRoamingEnabledChanged()
1356+ {
1357+ auto idx = findSim(sender());
1358+ p.dataChanged(idx, idx, {SimsListModel::Roles::RoleDataRoamingEnabled});
1359+ }
1360+
1361+ void propertyChanged(const QString& name, const QVariant& value)
1362+ {
1363+ if (name == "Sims")
1364+ {
1365+ QList<QDBusObjectPath> tmp;
1366+ qvariant_cast<QDBusArgument>(value) >> tmp;
1367+ updateSimDBusPaths(tmp);
1368+ }
1369+ }
1370+
1371+public:
1372+ SimsListModel& p;
1373+ function<void(QObject*)> m_objectOwner;
1374+ QList<QDBusObjectPath> m_dbus_paths;
1375+ QList<Sim::SPtr> m_sims;
1376+
1377+ shared_ptr<ComUbuntuConnectivity1PrivateInterface> m_writeInterface;
1378+ internal::DBusPropertyCache::SPtr m_propertyCache;
1379+};
1380+
1381+SimsListModel::SimsListModel(const internal::SimsListModelParameters &parameters) :
1382+ QAbstractListModel(0),
1383+ d(new Priv(*this))
1384+{
1385+ d->m_objectOwner = parameters.objectOwner;
1386+ d->m_writeInterface = parameters.writeInterface;
1387+ d->m_propertyCache = parameters.propertyCache;
1388+
1389+ connect(d->m_propertyCache.get(),
1390+ &internal::DBusPropertyCache::propertyChanged, d.get(),
1391+ &Priv::propertyChanged);
1392+
1393+ QList<QDBusObjectPath> tmp;
1394+ qvariant_cast<QDBusArgument>(d->m_propertyCache->get("Sims")) >> tmp;
1395+ d->updateSimDBusPaths(tmp);
1396+}
1397+
1398+SimsListModel::~SimsListModel()
1399+{
1400+}
1401+
1402+int SimsListModel::columnCount(const QModelIndex &) const
1403+{
1404+ return 1;
1405+}
1406+
1407+int SimsListModel::rowCount(const QModelIndex &) const
1408+{
1409+ return d->m_sims.size();
1410+}
1411+
1412+QVariant SimsListModel::data(const QModelIndex &index, int role) const
1413+{
1414+ int row(index.row());
1415+ if (row < 0 || row >= d->m_sims.size())
1416+ {
1417+ return QVariant();
1418+ }
1419+
1420+ auto sim = d->m_sims.value(row);
1421+
1422+ switch (role)
1423+ {
1424+ case Roles::RoleImsi:
1425+ return sim->imsi();
1426+ break;
1427+ case Roles::RolePrimaryPhoneNumber:
1428+ return sim->primaryPhoneNumber();
1429+ break;
1430+ case Roles::RolePhoneNumbers:
1431+ return QVariant::fromValue<QStringList>(sim->phoneNumbers());
1432+ break;
1433+ case RoleLocked:
1434+ return sim->locked();
1435+ break;
1436+ case RolePresent:
1437+ return sim->present();
1438+ break;
1439+ case Roles::RoleMcc:
1440+ return sim->mcc();
1441+ break;
1442+ case Roles::RoleMnc:
1443+ return sim->mnc();
1444+ case Roles::RolePreferredLanguages:
1445+ return QVariant::fromValue<QStringList>(sim->preferredLanguages());
1446+ break;
1447+ case Roles::RoleDataRoamingEnabled:
1448+ return sim->dataRoamingEnabled();
1449+ break;
1450+ case Roles::RoleSimObject:
1451+ return QVariant::fromValue<Sim*>(sim.get());
1452+ break;
1453+ }
1454+
1455+
1456+ return QVariant();
1457+}
1458+
1459+Sim::SPtr SimsListModel::getSimByPath(const QDBusObjectPath &path) const
1460+{
1461+ for (auto sim : d->m_sims)
1462+ {
1463+ if (sim->path() == path) {
1464+ return sim;
1465+ }
1466+ }
1467+ return nullptr;
1468+}
1469+
1470+
1471+}
1472+
1473+#include "sims-list-model.moc"
1474
1475=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h'
1476--- src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h 1970-01-01 00:00:00 +0000
1477+++ src/connectivity-api/connectivity-qt/connectivityqt/sims-list-model.h 2016-05-26 13:16:24 +0000
1478@@ -0,0 +1,101 @@
1479+/*
1480+ * Copyright © 2016 Canonical Ltd.
1481+ *
1482+ * This program is free software: you can redistribute it and/or modify it
1483+ * under the terms of the GNU Lesser General Public License version 3,
1484+ * as published by the Free Software Foundation.
1485+ *
1486+ * This program is distributed in the hope that it will be useful,
1487+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1488+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1489+ * GNU Lesser General Public License for more details.
1490+ *
1491+ * You should have received a copy of the GNU Lesser General Public License
1492+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1493+ *
1494+ * Authors:
1495+ * Antti Kaijanmäki <antti.kaijanmaki@canonical.com>
1496+ */
1497+
1498+#pragma once
1499+
1500+#include <QAbstractItemModel>
1501+#include <QDBusConnection>
1502+#include <QDBusObjectPath>
1503+#include <connectivityqt/sim.h>
1504+
1505+#include <unity/util/DefinesPtrs.h>
1506+
1507+#include <memory>
1508+
1509+namespace connectivityqt
1510+{
1511+namespace internal
1512+{
1513+struct SimsListModelParameters;
1514+}
1515+
1516+class Q_DECL_EXPORT SimsListModel : public QAbstractListModel
1517+{
1518+ Q_OBJECT
1519+
1520+ Q_ENUMS(Roles)
1521+
1522+public:
1523+
1524+ UNITY_DEFINES_PTRS(SimsListModel);
1525+
1526+ enum Roles
1527+ {
1528+ RoleImsi = Qt::UserRole + 1,
1529+ RolePrimaryPhoneNumber,
1530+ RolePhoneNumbers,
1531+ RoleLocked,
1532+ RolePresent,
1533+ RoleMcc,
1534+ RoleMnc,
1535+ RolePreferredLanguages,
1536+ RoleDataRoamingEnabled,
1537+ RoleSimObject
1538+ };
1539+
1540+ SimsListModel(const internal::SimsListModelParameters& parameters);
1541+
1542+ ~SimsListModel();
1543+
1544+ int columnCount(const QModelIndex &parent) const override;
1545+
1546+ int rowCount(const QModelIndex &parent) const override;
1547+
1548+ QVariant data(const QModelIndex &index, int role) const override;
1549+
1550+ QHash<int, QByteArray> roleNames() const override
1551+ {
1552+ QHash<int, QByteArray> roles;
1553+ roles[RoleImsi] = "Imsi";
1554+ roles[RolePrimaryPhoneNumber] = "PrimaryPhoneNumber";
1555+ roles[RolePhoneNumbers] = "PhoneNumbers";
1556+ roles[RoleLocked] = "Locked";
1557+ roles[RolePresent] = "Present";
1558+ roles[RoleMcc] = "Mcc";
1559+ roles[RoleMnc] = "Mnc";
1560+ roles[RolePreferredLanguages] = "PreferredLanguages";
1561+ roles[RoleDataRoamingEnabled] = "DataRoamingEnabled";
1562+ roles[RoleSimObject] = "SimObject";
1563+ return roles;
1564+ }
1565+
1566+ Sim::SPtr getSimByPath(const QDBusObjectPath &path) const;
1567+
1568+public Q_SLOTS:
1569+
1570+Q_SIGNALS:
1571+
1572+ void simsUpdated();
1573+
1574+protected:
1575+ class Priv;
1576+ std::shared_ptr<Priv> d;
1577+};
1578+
1579+}
1580
1581=== modified file 'src/indicator/nmofono/manager-impl.cpp'
1582--- src/indicator/nmofono/manager-impl.cpp 2016-05-26 13:16:24 +0000
1583+++ src/indicator/nmofono/manager-impl.cpp 2016-05-26 13:16:24 +0000
1584@@ -310,6 +310,7 @@
1585 m_ofonoLinks[path] = modem;
1586 connect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock);
1587 connect(modem.get(), &wwan::Modem::ready, this, &Private::modemReady);
1588+ matchModemsAndSims();
1589 }
1590
1591 Q_EMIT p.linksUpdated();

Subscribers

People subscribed via source and target branches