Connect hardware change signals

pull/1/head
Timothy Pearson 12 years ago
parent 1a6fd0dfad
commit 2a9e4eac1f

@ -67,13 +67,11 @@ DeviceTrayComponent::DeviceTrayComponent(TQString device, KSystemTray * parent,
: TrayComponent(parent, name), m_device(device) : TrayComponent(parent, name), m_device(device)
{ {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
// TDENM FIXME // Listen for hardware change events
// This TQt connection will need to be re-established whenever the device list changes, e.g. after a call to TDEHardwareDevices::queryHardwareInformation() connect(hwdevices, TQT_SIGNAL(hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString)), this, TQT_SLOT(tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString)));
// Therefore, this class should listen to hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString) and reload devices if TDEHardwareEvent::HardwareListModified is passed // Trigger an initial hardware information update
connect(deviceConnMan, TQT_SIGNAL(StateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus)), TQT_SLOT(deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus))); tdeHardwareEventHandler(TDEHardwareEvent::HardwareListModified, TQString::null);
m_pixmaps[TDENetworkConnectionStatus::Invalid] = "nm_no_connection"; m_pixmaps[TDENetworkConnectionStatus::Invalid] = "nm_no_connection";
m_pixmaps[TDENetworkConnectionStatus::UnManaged] = "nm_no_connection"; m_pixmaps[TDENetworkConnectionStatus::UnManaged] = "nm_no_connection";
@ -108,6 +106,17 @@ TQString DeviceTrayComponent::device() const
return m_device; return m_device;
} }
void DeviceTrayComponent::tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent event, TQString)
{
if (event == TDEHardwareEvent::HardwareListModified) {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
connect(deviceConnMan, TQT_SIGNAL(networkDeviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)), TQT_SLOT(deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)));
}
}
TQStringList DeviceTrayComponent::getToolTipText() TQStringList DeviceTrayComponent::getToolTipText()
{ {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
@ -154,15 +163,19 @@ void DeviceTrayComponent::setPixmapForState(TDENetworkConnectionStatus::TDENetwo
m_pixmaps[state] = pixmap; m_pixmaps[state] = pixmap;
} }
void DeviceTrayComponent::deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) void DeviceTrayComponent::deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress)
{ {
// TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
// TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device)); TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
if (dev->macAddress() != hwAddress) {
printf("[WARNING] Got networkDeviceStateChanged signal for HW address '%s', but my HW address is '%s'! Ignoring...\n\r", hwAddress.ascii(), dev->macAddress().ascii());
}
//check if our device now holds the default active connection //check if our device now holds the default active connection
// if it is the default active connection // if it is the default active connection
// or if it is activating. what if 2 devices are activating simultaneously? // or if it is activating. what if 2 devices are activating simultaneously?
switch (state) { switch (newState) {
case TDENetworkConnectionStatus::EstablishingLink: case TDENetworkConnectionStatus::EstablishingLink:
emit needsCenterStage(this, true); emit needsCenterStage(this, true);
break; break;

@ -54,7 +54,10 @@ class DeviceTrayComponent : public TrayComponent
virtual void newConnection() = 0; virtual void newConnection() = 0;
protected slots: protected slots:
void deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString);
private slots:
void tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString);
protected: protected:
void setMovieForState(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString); void setMovieForState(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString);

@ -293,14 +293,18 @@ void WirelessDeviceTray::setPixmapForStates(TDENetworkConnectionStatus::TDENetwo
} }
} }
void WirelessDeviceTray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) void WirelessDeviceTray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress)
{ {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev)); TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
if (dev->macAddress() != hwAddress) {
printf("[WARNING] Got networkDeviceStateChanged signal for HW address '%s', but my HW address is '%s'! Ignoring...\n\r", hwAddress.ascii(), dev->macAddress().ascii());
}
slotCheckActiveAccessPoint(); slotCheckActiveAccessPoint();
if (state == TDENetworkConnectionStatus::Connected) { if (newState == TDENetworkConnectionStatus::Connected) {
// trigger an update of the connections seen bssids property // trigger an update of the connections seen bssids property
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager(); TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
TDENetworkWiFiAPInfo * ap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID); TDENetworkWiFiAPInfo * ap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID);
@ -308,19 +312,19 @@ void WirelessDeviceTray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENe
int strength = (ap->signalQuality*100.0); int strength = (ap->signalQuality*100.0);
if (strength > 80) { if (strength > 80) {
setPixmapForStates(state, "nm_signal_100"); setPixmapForStates(newState, "nm_signal_100");
} }
else if (strength > 55) { else if (strength > 55) {
setPixmapForStates(state, "nm_signal_75"); setPixmapForStates(newState, "nm_signal_75");
} }
else if (strength > 30) { else if (strength > 30) {
setPixmapForStates(state, "nm_signal_50"); setPixmapForStates(newState, "nm_signal_50");
} }
else if (strength > 5) { else if (strength > 5) {
setPixmapForStates(state, "nm_signal_25"); setPixmapForStates(newState, "nm_signal_25");
} }
else { else {
setPixmapForStates(state, "nm_signal_00"); setPixmapForStates(newState, "nm_signal_00");
} }
} }
} }
@ -346,13 +350,8 @@ void WirelessDeviceTray::slotCheckActiveAccessPoint()
if (active_conn && deviceConnMan->deviceInformation().statusFlags == TDENetworkConnectionStatus::Connected) { if (active_conn && deviceConnMan->deviceInformation().statusFlags == TDENetworkConnectionStatus::Connected) {
TDENetworkWiFiAPInfo * activeap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID); TDENetworkWiFiAPInfo * activeap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID);
if ( activeap != d->activeAccessPoint) { if ( activeap != d->activeAccessPoint) {
if (!d->activeAccessPoint.isNull()) {
disconnect( deviceConnMan, TQT_SIGNAL(accessPointStatusChanged(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)), this, TQT_SLOT(apPropertyChanged(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)));
}
d->activeAccessPoint = activeap; d->activeAccessPoint = activeap;
if ( d->activeAccessPoint ) { if ( d->activeAccessPoint ) {
connect( deviceConnMan, TQT_SIGNAL(accessPointStatusChanged(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)), this, TQT_SLOT(apPropertyChanged(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)));
TDEWiFiConnection* wireless = dynamic_cast<TDEWiFiConnection*>(active_conn); TDEWiFiConnection* wireless = dynamic_cast<TDEWiFiConnection*>(active_conn);
if (wireless) { if (wireless) {
if (!(wireless->heardBSSIDs.contains(d->activeAccessPoint->BSSID))) { if (!(wireless->heardBSSIDs.contains(d->activeAccessPoint->BSSID))) {
@ -401,11 +400,48 @@ void WirelessDeviceTray::slotAccessPointAdded(TDENetworkWiFiAPInfo* ap)
KNotifyClient::event( tray()->winId(), "knm-nm-network-found", i18n("TDENetworkManager New Wireless Network Found") ); KNotifyClient::event( tray()->winId(), "knm-nm-network-found", i18n("TDENetworkManager New Wireless Network Found") );
} }
void WirelessDeviceTray::slotAccessPointRemoved(const TQString&) void WirelessDeviceTray::slotAccessPointRemoved(TDEMACAddress)
{ {
KNotifyClient::event( tray()->winId(), "knm-nm-network-gone", i18n("TDENetworkManager Wireless Network Disappeared") ); KNotifyClient::event( tray()->winId(), "knm-nm-network-gone", i18n("TDENetworkManager Wireless Network Disappeared") );
} }
void WirelessDeviceTray::tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent event, TQString)
{
if (event == TDEHardwareEvent::HardwareListModified) {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
// get notified when the device state changes
connect(deviceConnMan, TQT_SIGNAL(networkDeviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)), this, TQT_SLOT(slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)));
// get notified of all AP changes
connect(deviceConnMan, TQT_SIGNAL(accessPointStatusChanged(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)), this, TQT_SLOT(tdeAccessPointStatusChangedHandler(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType)));
}
}
void WirelessDeviceTray::tdeAccessPointStatusChangedHandler(TDEMACAddress BSSID, TDENetworkAPEventType::TDENetworkAPEventType event) {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
if (event == TDENetworkAPEventType::Discovered) {
TDENetworkWiFiAPInfo* apinfo = deviceConnMan->findAccessPointByBSSID(BSSID);
slotAccessPointAdded(apinfo);
}
else if (event == TDENetworkAPEventType::Lost) {
slotAccessPointRemoved(BSSID);
}
else if (event == TDENetworkAPEventType::SignalStrengthChanged) {
if (deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID == BSSID) {
apPropertyChanged(BSSID, event);
}
}
else if (event == TDENetworkAPEventType::AccessPointChanged) {
slotCheckActiveAccessPoint();
}
}
WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, const char * name) WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, const char * name)
: DeviceTrayComponent (dev, parent, name) : DeviceTrayComponent (dev, parent, name)
{ {
@ -413,7 +449,6 @@ WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, cons
d->dev = dev; d->dev = dev;
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* hwdev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
// we want other icons for wireless devices // we want other icons for wireless devices
setPixmapForState(TDENetworkConnectionStatus::Invalid, "wireless_off"); setPixmapForState(TDENetworkConnectionStatus::Invalid, "wireless_off");
@ -422,19 +457,10 @@ WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, cons
setPixmapForState(TDENetworkConnectionStatus::Disconnected, "wireless"); setPixmapForState(TDENetworkConnectionStatus::Disconnected, "wireless");
setPixmapForState(TDENetworkConnectionStatus::Connected, "nm_signal_50"); setPixmapForState(TDENetworkConnectionStatus::Connected, "nm_signal_50");
// TDENM FIXME // Listen for hardware change events
// These TQt connections will need to be re-established whenever the device list changes, e.g. after a call to TDEHardwareDevices::queryHardwareInformation() connect(hwdevices, TQT_SIGNAL(hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString)), this, TQT_SLOT(tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString)));
// Therefore, this class should listen to hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString) and reload devices if TDEHardwareEvent::HardwareListModified is passed // Trigger an initial hardware information update
tdeHardwareEventHandler(TDEHardwareEvent::HardwareListModified, TQString::null);
// get notified when the device state changes
connect(hwdev, TQT_SIGNAL(StateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus)), this, TQT_SLOT(slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus)));
// if the active access point changed but not the connection we roamed to a new AP
connect(hwdev, TQT_SIGNAL(propertiesChanged()), this, TQT_SLOT(slotCheckActiveAccessPoint()));
// get notified of all AP changes
connect(hwdev, TQT_SIGNAL(accessPointAdded(TDENetworkWiFiAPInfo*)), this, TQT_SLOT(slotAccessPointAdded(TDENetworkWiFiAPInfo*)));
connect(hwdev, TQT_SIGNAL(accessPointRemoved(const TQString&)), this, TQT_SLOT(slotAccessPointRemoved(const TQString&)));
} }
WirelessDeviceTray::~WirelessDeviceTray () WirelessDeviceTray::~WirelessDeviceTray ()

@ -54,13 +54,18 @@ class WirelessDeviceTray : public DeviceTrayComponent
TQStringList getToolTipText(); TQStringList getToolTipText();
public slots: public slots:
void slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString);
void slotCheckActiveAccessPoint(); void slotCheckActiveAccessPoint();
void newConnection(); void newConnection();
protected slots: protected slots:
void apPropertyChanged(TDEMACAddress BSSID, TDENetworkAPEventType::TDENetworkAPEventType event); void apPropertyChanged(TDEMACAddress BSSID, TDENetworkAPEventType::TDENetworkAPEventType event);
void slotAccessPointAdded(TDENetworkWiFiAPInfo*); void slotAccessPointAdded(TDENetworkWiFiAPInfo*);
void slotAccessPointRemoved(const TQString&); void slotAccessPointRemoved(TDEMACAddress);
private slots:
void tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString);
void tdeAccessPointStatusChangedHandler(TDEMACAddress, TDENetworkAPEventType::TDENetworkAPEventType);
private: private:
void addWirelessNetworks(KPopupMenu* menu); void addWirelessNetworks(KPopupMenu* menu);

Loading…
Cancel
Save