Skip to content

Commit

Permalink
Merge pull request nemomobile#3 from ftonello/scan
Browse files Browse the repository at this point in the history
technology: Added qml signal support to scan
  • Loading branch information
rojkov committed Dec 1, 2012
2 parents 0b05214 + f227bc7 commit e7a80fc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 28 deletions.
18 changes: 16 additions & 2 deletions libconnman-qt/networktechnology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const QString NetworkTechnology::Connected("Connected");

NetworkTechnology::NetworkTechnology(const QString &path, const QVariantMap &properties, QObject* parent)
: QObject(parent),
m_technology(NULL)
m_technology(NULL),
m_scanWatcher(NULL)
{
Q_ASSERT(!path.isEmpty());
m_technology = new Technology("net.connman", path, QDBusConnection::systemBus(), this);
Expand Down Expand Up @@ -80,7 +81,11 @@ void NetworkTechnology::setPowered(const bool &powered)
void NetworkTechnology::scan()
{
Q_ASSERT(m_technology);
m_technology->Scan();

QDBusPendingReply<> reply = m_technology->Scan();
m_scanWatcher = new QDBusPendingCallWatcher(reply, m_technology);
connect(m_scanWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(scanReply(QDBusPendingCallWatcher*)));
}

// Private
Expand All @@ -102,3 +107,12 @@ void NetworkTechnology::propertyChanged(const QString &name, const QDBusVariant
emit connectedChanged(tmp.toBool());
}
}

void NetworkTechnology::scanReply(QDBusPendingCallWatcher *call)
{
Q_UNUSED(call);

pr_dbg() << "Scan Finished";

emit scanFinished();
}
3 changes: 3 additions & 0 deletions libconnman-qt/networktechnology.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public slots:
signals:
void poweredChanged(const bool &powered);
void connectedChanged(const bool &connected);
void scanFinished();

private:
Technology *m_technology;
QVariantMap m_propertiesCache;
QDBusPendingCallWatcher *m_scanWatcher;

static const QString Name;
static const QString Type;
Expand All @@ -52,6 +54,7 @@ public slots:

private slots:
void propertyChanged(const QString &name, const QDBusVariant &value);
void scanReply(QDBusPendingCallWatcher *call);

private:
Q_DISABLE_COPY(NetworkTechnology);
Expand Down
52 changes: 28 additions & 24 deletions plugin/networkingmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@

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

#define CONNECT_WIFI_SIGNALS(wifi) \
connect(wifi, \
SIGNAL(poweredChanged(bool)), \
this, \
SIGNAL(wifiPoweredChanged(bool))); \
connect(wifi, \
SIGNAL(scanFinished()), \
this, \
SIGNAL(scanRequestFinished()))

NetworkingModel::NetworkingModel(QObject* parent)
: QObject(parent),
m_manager(NULL),
Expand All @@ -24,10 +34,7 @@ NetworkingModel::NetworkingModel(QObject* parent)

m_wifi = m_manager->getTechnology("wifi"); // TODO: use constant literal
if (m_wifi) {
connect(m_wifi,
SIGNAL(poweredChanged(bool)),
this,
SIGNAL(wifiPoweredChanged(bool)));
CONNECT_WIFI_SIGNALS(m_wifi);
}

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

void NetworkingModel::updateTechnologies()
{
NetworkTechnology *test = NULL;
if (m_wifi) {
if ((test = m_manager->getTechnology("wifi")) == NULL) {
// if wifi is set and manager doesn't return a wifi, it means
// that wifi was removed
m_wifi = NULL;
}
} else {
if (test = m_manager->getTechnology("wifi")) {
// if wifi is not set and manager returns a wifi, it means
// that wifi was added
m_wifi = test;

connect(m_wifi,
SIGNAL(poweredChanged(bool)),
this,
SIGNAL(wifiPoweredChanged(bool)));
}
}
NetworkTechnology *test = NULL;
if (m_wifi) {
if ((test = m_manager->getTechnology("wifi")) == NULL) {
// if wifi is set and manager doesn't return a wifi, it means
// that wifi was removed
m_wifi = NULL;
}
} else {
if (test = m_manager->getTechnology("wifi")) {
// if wifi is not set and manager returns a wifi, it means
// that wifi was added
m_wifi = test;

CONNECT_WIFI_SIGNALS(m_wifi);
}
}

emit technologiesChanged();
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/networkingmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class NetworkingModel : public QObject
Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged);
Q_PROPERTY(bool wifiPowered READ isWifiPowered WRITE setWifiPowered NOTIFY wifiPoweredChanged);
Q_PROPERTY(QList<QObject*> networks READ networks NOTIFY networksChanged);
Q_PROPERTY(NOTIFY scanRequestFinished);

public:
NetworkingModel(QObject* parent=0);
Expand All @@ -54,6 +55,7 @@ public slots:
void technologiesChanged();
void userInputRequested(QVariantMap fields);
void errorReported(const QString &error);
void scanRequestFinished();

private:
NetworkManager* m_manager;
Expand All @@ -62,7 +64,6 @@ public slots:

private slots:
void updateTechnologies();

void managerAvailabilityChanged(bool available);

private:
Expand Down
17 changes: 16 additions & 1 deletion test/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ PageStack {
running: false
repeat: true
triggeredOnStart: true
onTriggered: networkingModel.requestScan();
onTriggered: {
networkingModel.requestScan();
txtScanning.text = "Scanning...";
}
}

NetworkingModel {
Expand Down Expand Up @@ -75,6 +78,11 @@ PageStack {
scanTimer.running = networkingModel.wifiPowered;
}

onScanRequestFinished: {
txtScanning.text = "";
console.log("scan finished");
}

onUserInputRequested: {
scanTimer.running = false;
scanTimer.triggeredOnStart = false;
Expand Down Expand Up @@ -158,6 +166,13 @@ PageStack {
color: "white"
font.pointSize: 16
}
Text {
id: txtScanning
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 }
text: ""
color: "red"
font.pointSize: 13
}
Switch {
id: wifiSwitch
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 40 }
Expand Down

0 comments on commit e7a80fc

Please sign in to comment.