add ap properties changed signal

Change-Id: I63d139f30f47231c7b9d38270b3e6f49cd2fa534
This commit is contained in:
石博文 2016-07-27 17:19:15 +08:00 committed by Hualet Wang
parent 91eee633dd
commit 5a20ec0cab
4 changed files with 46 additions and 6 deletions

View File

@ -22,6 +22,11 @@ AccessPoint::AccessPoint(const QString &info)
loadApInfo(doc.object());
}
AccessPoint::AccessPoint()
{
}
bool AccessPoint::operator==(const AccessPoint &ap) const
{
return m_ssid == ap.m_ssid;

View File

@ -11,6 +11,7 @@ class AccessPoint : public QObject
public:
explicit AccessPoint(const QJsonObject &apInfo);
explicit AccessPoint(const QString &info);
explicit AccessPoint();
AccessPoint(const AccessPoint &ap);
bool operator==(const AccessPoint &ap) const;
bool operator>(const AccessPoint &ap) const;

View File

@ -11,6 +11,7 @@ WirelessApplet::WirelessApplet(const QSet<NetworkDevice>::const_iterator &device
: QScrollArea(parent),
m_device(*deviceIter),
m_activeAP(),
m_updateAPTimer(new QTimer(this)),
@ -50,10 +51,16 @@ WirelessApplet::WirelessApplet(const QSet<NetworkDevice>::const_iterator &device
connect(m_updateAPTimer, &QTimer::timeout, this, &WirelessApplet::updateAPList);
}
NetworkDevice::NetworkState WirelessApplet::wirelessState() const
{
return m_device.state();
}
void WirelessApplet::init()
{
setDeviceInfo();
loadAPList();
onActiveAPChanged();
}
void WirelessApplet::APAdded(const QString &devPath, const QString &info)
@ -121,7 +128,10 @@ void WirelessApplet::APPropertiesChanged(const QString &devPath, const QString &
if (*it > ap)
{
*it = ap;
m_activeAP = ap;
m_updateAPTimer->start();
emit activeAPChanged();
}
}
@ -181,17 +191,37 @@ void WirelessApplet::deviceStateChanegd()
const QJsonObject info = wireless.toObject();
if (info.value("Path") == m_device.path())
{
NetworkDevice dev = NetworkDevice(NetworkDevice::Wireless, info);
NetworkDevice prevInfo = m_device;
m_device = NetworkDevice(NetworkDevice::Wireless, info);
if (dev.state() != m_device.state())
emit wirelessStateChanged(dev.state());
if (dev.activeAp() != m_device.activeAp())
emit activeAPChanged();
if (prevInfo.state() != m_device.state())
emit wirelessStateChanged(m_device.state());
if (prevInfo.activeAp() != m_device.activeAp())
onActiveAPChanged();
m_device = dev;
break;
}
}
}
}
void WirelessApplet::onActiveAPChanged()
{
const QJsonDocument doc = QJsonDocument::fromJson(m_networkInter->GetAccessPoints(m_device.dbusPath()).value().toUtf8());
Q_ASSERT(doc.isArray());
for (auto dev : doc.array())
{
Q_ASSERT(dev.isObject());
const QJsonObject obj = dev.toObject();
if (obj.value("Path").toString() != m_device.activeAp())
continue;
m_activeAP = AccessPoint(obj);
break;
}
emit activeAPChanged();
}

View File

@ -18,6 +18,8 @@ class WirelessApplet : public QScrollArea
public:
explicit WirelessApplet(const QSet<NetworkDevice>::const_iterator &deviceIter, QWidget *parent = 0);
NetworkDevice::NetworkState wirelessState() const;
signals:
void wirelessStateChanged(const NetworkDevice::NetworkState state) const;
void activeAPChanged() const;
@ -34,10 +36,12 @@ private slots:
void updateAPList();
void deviceEnableChanged(const bool enable);
void deviceStateChanegd();
void onActiveAPChanged();
private:
NetworkDevice m_device;
AccessPoint m_activeAP;
QList<AccessPoint> m_apList;
QTimer *m_updateAPTimer;