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)
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
// TDENM FIXME
// This TQt connection will need to be re-established whenever the device list changes, e.g. after a call to TDEHardwareDevices::queryHardwareInformation()
// Therefore, this class should listen to hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString) and reload devices if TDEHardwareEvent::HardwareListModified is passed
connect(deviceConnMan, TQT_SIGNAL(StateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus)), TQT_SLOT(deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus)));
// Listen for hardware change events
connect(hwdevices, TQT_SIGNAL(hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString)), this, TQT_SLOT(tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString)));
// Trigger an initial hardware information update
tdeHardwareEventHandler(TDEHardwareEvent::HardwareListModified, TQString::null);
m_pixmaps[TDENetworkConnectionStatus::Invalid] = "nm_no_connection";
m_pixmaps[TDENetworkConnectionStatus::UnManaged] = "nm_no_connection";
@ -108,6 +106,17 @@ TQString DeviceTrayComponent::device() const
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()
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
@ -154,15 +163,19 @@ void DeviceTrayComponent::setPixmapForState(TDENetworkConnectionStatus::TDENetwo
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();
// TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
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
// if it is the default active connection
// or if it is activating. what if 2 devices are activating simultaneously?
switch (state) {
switch (newState) {
case TDENetworkConnectionStatus::EstablishingLink:
emit needsCenterStage(this, true);
break;

@ -54,7 +54,10 @@ class DeviceTrayComponent : public TrayComponent
virtual void newConnection() = 0;
protected slots:
void deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus);
void deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString);
private slots:
void tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString);
protected:
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();
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();
if (state == TDENetworkConnectionStatus::Connected) {
if (newState == TDENetworkConnectionStatus::Connected) {
// trigger an update of the connections seen bssids property
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
TDENetworkWiFiAPInfo * ap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID);
@ -308,19 +312,19 @@ void WirelessDeviceTray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENe
int strength = (ap->signalQuality*100.0);
if (strength > 80) {
setPixmapForStates(state, "nm_signal_100");
setPixmapForStates(newState, "nm_signal_100");
}
else if (strength > 55) {
setPixmapForStates(state, "nm_signal_75");
setPixmapForStates(newState, "nm_signal_75");
}
else if (strength > 30) {
setPixmapForStates(state, "nm_signal_50");
setPixmapForStates(newState, "nm_signal_50");
}
else if (strength > 5) {
setPixmapForStates(state, "nm_signal_25");
setPixmapForStates(newState, "nm_signal_25");
}
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) {
TDENetworkWiFiAPInfo * activeap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID);
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;
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);
if (wireless) {
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") );
}
void WirelessDeviceTray::slotAccessPointRemoved(const TQString&)
void WirelessDeviceTray::slotAccessPointRemoved(TDEMACAddress)
{
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)
: DeviceTrayComponent (dev, parent, name)
{
@ -413,7 +449,6 @@ WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, cons
d->dev = dev;
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDENetworkDevice* hwdev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
// we want other icons for wireless devices
setPixmapForState(TDENetworkConnectionStatus::Invalid, "wireless_off");
@ -422,19 +457,10 @@ WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, cons
setPixmapForState(TDENetworkConnectionStatus::Disconnected, "wireless");
setPixmapForState(TDENetworkConnectionStatus::Connected, "nm_signal_50");
// TDENM FIXME
// These TQt connections will need to be re-established whenever the device list changes, e.g. after a call to TDEHardwareDevices::queryHardwareInformation()
// Therefore, this class should listen to hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString) and reload devices if TDEHardwareEvent::HardwareListModified is passed
// 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&)));
// Listen for hardware change events
connect(hwdevices, TQT_SIGNAL(hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString)), this, TQT_SLOT(tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEvent, TQString)));
// Trigger an initial hardware information update
tdeHardwareEventHandler(TDEHardwareEvent::HardwareListModified, TQString::null);
}
WirelessDeviceTray::~WirelessDeviceTray ()

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

Loading…
Cancel
Save