Skip to content

Commit e7a80fc

Browse files
committed
Merge pull request nemomobile#3 from ftonello/scan
technology: Added qml signal support to scan
2 parents 0b05214 + f227bc7 commit e7a80fc

File tree

5 files changed

+65
-28
lines changed

5 files changed

+65
-28
lines changed

libconnman-qt/networktechnology.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const QString NetworkTechnology::Connected("Connected");
1818

1919
NetworkTechnology::NetworkTechnology(const QString &path, const QVariantMap &properties, QObject* parent)
2020
: QObject(parent),
21-
m_technology(NULL)
21+
m_technology(NULL),
22+
m_scanWatcher(NULL)
2223
{
2324
Q_ASSERT(!path.isEmpty());
2425
m_technology = new Technology("net.connman", path, QDBusConnection::systemBus(), this);
@@ -80,7 +81,11 @@ void NetworkTechnology::setPowered(const bool &powered)
8081
void NetworkTechnology::scan()
8182
{
8283
Q_ASSERT(m_technology);
83-
m_technology->Scan();
84+
85+
QDBusPendingReply<> reply = m_technology->Scan();
86+
m_scanWatcher = new QDBusPendingCallWatcher(reply, m_technology);
87+
connect(m_scanWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
88+
this, SLOT(scanReply(QDBusPendingCallWatcher*)));
8489
}
8590

8691
// Private
@@ -102,3 +107,12 @@ void NetworkTechnology::propertyChanged(const QString &name, const QDBusVariant
102107
emit connectedChanged(tmp.toBool());
103108
}
104109
}
110+
111+
void NetworkTechnology::scanReply(QDBusPendingCallWatcher *call)
112+
{
113+
Q_UNUSED(call);
114+
115+
pr_dbg() << "Scan Finished";
116+
117+
emit scanFinished();
118+
}

libconnman-qt/networktechnology.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ public slots:
4040
signals:
4141
void poweredChanged(const bool &powered);
4242
void connectedChanged(const bool &connected);
43+
void scanFinished();
4344

4445
private:
4546
Technology *m_technology;
4647
QVariantMap m_propertiesCache;
48+
QDBusPendingCallWatcher *m_scanWatcher;
4749

4850
static const QString Name;
4951
static const QString Type;
@@ -52,6 +54,7 @@ public slots:
5254

5355
private slots:
5456
void propertyChanged(const QString &name, const QDBusVariant &value);
57+
void scanReply(QDBusPendingCallWatcher *call);
5558

5659
private:
5760
Q_DISABLE_COPY(NetworkTechnology);

plugin/networkingmodel.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313

1414
static const char AGENT_PATH[] = "/WifiSettings";
1515

16+
#define CONNECT_WIFI_SIGNALS(wifi) \
17+
connect(wifi, \
18+
SIGNAL(poweredChanged(bool)), \
19+
this, \
20+
SIGNAL(wifiPoweredChanged(bool))); \
21+
connect(wifi, \
22+
SIGNAL(scanFinished()), \
23+
this, \
24+
SIGNAL(scanRequestFinished()))
25+
1626
NetworkingModel::NetworkingModel(QObject* parent)
1727
: QObject(parent),
1828
m_manager(NULL),
@@ -24,10 +34,7 @@ NetworkingModel::NetworkingModel(QObject* parent)
2434

2535
m_wifi = m_manager->getTechnology("wifi"); // TODO: use constant literal
2636
if (m_wifi) {
27-
connect(m_wifi,
28-
SIGNAL(poweredChanged(bool)),
29-
this,
30-
SIGNAL(wifiPoweredChanged(bool)));
37+
CONNECT_WIFI_SIGNALS(m_wifi);
3138
}
3239

3340
connect(m_manager, SIGNAL(availabilityChanged(bool)),
@@ -63,7 +70,7 @@ QList<QObject*> NetworkingModel::networks() const
6370
// FIXME: how to get rid of this douple looping since we
6471
// must return a QList<QObject*>?
6572
foreach (NetworkService* network, m_manager->getServices("wifi")) {
66-
networks.append(network);
73+
networks.append(network);
6774
}
6875
return networks;
6976
}
@@ -97,25 +104,22 @@ void NetworkingModel::requestScan() const
97104

98105
void NetworkingModel::updateTechnologies()
99106
{
100-
NetworkTechnology *test = NULL;
101-
if (m_wifi) {
102-
if ((test = m_manager->getTechnology("wifi")) == NULL) {
103-
// if wifi is set and manager doesn't return a wifi, it means
104-
// that wifi was removed
105-
m_wifi = NULL;
106-
}
107-
} else {
108-
if (test = m_manager->getTechnology("wifi")) {
109-
// if wifi is not set and manager returns a wifi, it means
110-
// that wifi was added
111-
m_wifi = test;
112-
113-
connect(m_wifi,
114-
SIGNAL(poweredChanged(bool)),
115-
this,
116-
SIGNAL(wifiPoweredChanged(bool)));
117-
}
118-
}
107+
NetworkTechnology *test = NULL;
108+
if (m_wifi) {
109+
if ((test = m_manager->getTechnology("wifi")) == NULL) {
110+
// if wifi is set and manager doesn't return a wifi, it means
111+
// that wifi was removed
112+
m_wifi = NULL;
113+
}
114+
} else {
115+
if (test = m_manager->getTechnology("wifi")) {
116+
// if wifi is not set and manager returns a wifi, it means
117+
// that wifi was added
118+
m_wifi = test;
119+
120+
CONNECT_WIFI_SIGNALS(m_wifi);
121+
}
122+
}
119123

120124
emit technologiesChanged();
121125
}

plugin/networkingmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class NetworkingModel : public QObject
3030
Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged);
3131
Q_PROPERTY(bool wifiPowered READ isWifiPowered WRITE setWifiPowered NOTIFY wifiPoweredChanged);
3232
Q_PROPERTY(QList<QObject*> networks READ networks NOTIFY networksChanged);
33+
Q_PROPERTY(NOTIFY scanRequestFinished);
3334

3435
public:
3536
NetworkingModel(QObject* parent=0);
@@ -54,6 +55,7 @@ public slots:
5455
void technologiesChanged();
5556
void userInputRequested(QVariantMap fields);
5657
void errorReported(const QString &error);
58+
void scanRequestFinished();
5759

5860
private:
5961
NetworkManager* m_manager;
@@ -62,7 +64,6 @@ public slots:
6264

6365
private slots:
6466
void updateTechnologies();
65-
6667
void managerAvailabilityChanged(bool available);
6768

6869
private:

test/main.qml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ PageStack {
2626
running: false
2727
repeat: true
2828
triggeredOnStart: true
29-
onTriggered: networkingModel.requestScan();
29+
onTriggered: {
30+
networkingModel.requestScan();
31+
txtScanning.text = "Scanning...";
32+
}
3033
}
3134

3235
NetworkingModel {
@@ -75,6 +78,11 @@ PageStack {
7578
scanTimer.running = networkingModel.wifiPowered;
7679
}
7780

81+
onScanRequestFinished: {
82+
txtScanning.text = "";
83+
console.log("scan finished");
84+
}
85+
7886
onUserInputRequested: {
7987
scanTimer.running = false;
8088
scanTimer.triggeredOnStart = false;
@@ -158,6 +166,13 @@ PageStack {
158166
color: "white"
159167
font.pointSize: 16
160168
}
169+
Text {
170+
id: txtScanning
171+
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 }
172+
text: ""
173+
color: "red"
174+
font.pointSize: 13
175+
}
161176
Switch {
162177
id: wifiSwitch
163178
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 40 }

0 commit comments

Comments
 (0)