Fix wireless tray

pull/1/head
Timothy Pearson 12 years ago
parent 95063f60a5
commit cfa58d935e

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
TQString DeviceTrayComponent::pixmapForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) {
TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000;
while (flag != 0) {
while ((TQ_UINT32)flag > 0) {
if (state & flag) {
if (m_pixmaps.contains(flag)) {
return m_pixmaps[flag];
@ -39,7 +39,7 @@ TQString DeviceTrayComponent::pixmapForConnState(TDENetworkConnectionStatus::TDE
TQString DeviceTrayComponent::movieForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) {
TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000;
while (flag != 0) {
while ((TQ_UINT32)flag > 0) {
if (state & flag) {
if (m_movies.contains(flag)) {
return m_movies[flag];
@ -52,7 +52,7 @@ TQString DeviceTrayComponent::movieForConnState(TDENetworkConnectionStatus::TDEN
TQString DeviceTrayComponent::tooltipForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) {
TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000;
while (flag != 0) {
while ((TQ_UINT32)flag > 0) {
if (state & flag) {
if (m_tooltips.contains(flag)) {
return m_tooltips[flag];

@ -291,7 +291,6 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu)
if (!conn) {
continue;
}
if ((nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Disconnected)
|| (nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Invalid)) {
continue;
@ -324,10 +323,10 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu)
// offline vs. online mode
KAction* switch_mode = NULL;
if (nm->backendStatus() & TDENetworkGlobalManagerFlags::Sleeping) {
switch_mode = actionCollection ()->action ("offline_mode");
switch_mode = actionCollection ()->action ("online_mode");
}
else {
switch_mode = actionCollection ()->action ("online_mode");
switch_mode = actionCollection ()->action ("offline_mode");
}
disableStuffActionMenu->insert(switch_mode);
@ -373,6 +372,8 @@ Tray::slotStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlag
}
printf("NM state: %d\n\r", nm_state);
showActiveDeviceTray();
}
void
@ -541,6 +542,9 @@ void Tray::updateDeviceTrays()
// add the VPN componenet as it is not associated with a device
createVPNTrayComponent();
// show an active device if one is present
showActiveDeviceTray();
}
void Tray::mousePressEvent( TQMouseEvent *e )
@ -670,6 +674,51 @@ void Tray::trayUiChanged()
}
}
void Tray::showActiveDeviceTray() {
// If the current foreground tray device is deactivated, find the first active device and use it instead
bool needsNewDeviceTrayComponent = true;
if (d->foregroundTrayComponent) {
TDENetworkDevice* dtc_comp_dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->foregroundTrayComponent->device()));
TDENetworkConnectionManager* deviceConnMan = dtc_comp_dev->connectionManager();
TDENetworkConnectionStatus::TDENetworkConnectionStatus statusFlags = deviceConnMan->deviceInformation().statusFlags;
if ((statusFlags & TDENetworkConnectionStatus::Invalid) ||
(statusFlags & TDENetworkConnectionStatus::Disconnected)
) {
needsNewDeviceTrayComponent = true;
}
else {
needsNewDeviceTrayComponent = false;
}
}
if (needsNewDeviceTrayComponent) {
disconnectTrayDeviceManager();
for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) {
DeviceTrayComponent* newDtc = dynamic_cast<DeviceTrayComponent*> (*it);
if (newDtc) {
TDENetworkDevice* dtc_comp_dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(newDtc->device()));
TDENetworkConnectionManager* deviceConnMan = dtc_comp_dev->connectionManager();
TDENetworkConnectionStatus::TDENetworkConnectionStatus statusFlags = deviceConnMan->deviceInformation().statusFlags;
if ((statusFlags & TDENetworkConnectionStatus::Invalid) ||
(statusFlags & TDENetworkConnectionStatus::Disconnected)
) {
continue;
}
else {
d->foregroundTrayComponent = newDtc;
break;
}
}
}
connectTrayDeviceManager();
updateTrayDeviceManagerState();
}
trayUiChanged();
}
void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus state)
{
// Get all active connections
@ -701,6 +750,8 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
}
}
nm->loadConnectionInformation();
found_any_active_connection = 0;
// Get all active connections
allconmap = nm->connections();

@ -122,6 +122,7 @@ class Tray : public KSystemTray
void connectTrayDeviceManager();
void disconnectTrayDeviceManager();
void updateTrayDeviceManagerState();
void showActiveDeviceTray();
TrayPrivate* d;
TDEHardwareDevices* hwdevices;

@ -72,6 +72,8 @@ TQStringList WirelessDeviceTray::getToolTipText()
TDENetworkWiFiAPInfo * ap = deviceConnMan->findAccessPointByBSSID(deviceConnMan->deviceInformation().wiFiInfo.activeAccessPointBSSID);
if (ap) {
tooltip.append(i18n("Network: %1").arg(ap->friendlySSID()));
int strength = (ap->signalQuality*100.0);
tooltip.append(i18n("Signal Strength: %1%").arg(strength));
}
return tooltip;
@ -289,11 +291,11 @@ void WirelessDeviceTray::addMenuItems(KPopupMenu* menu)
void WirelessDeviceTray::setPixmapForStates(TDENetworkConnectionStatus::TDENetworkConnectionStatus states, TQString pixmap) {
TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000;
while (flag > 0) {
while ((TQ_UINT32)flag > 0) {
if (states & flag) {
setPixmapForState(flag, pixmap);
}
flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1);
flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1);
}
}
@ -413,13 +415,18 @@ void WirelessDeviceTray::tdeHardwareEventHandler(TDEHardwareEvent::TDEHardwareEv
{
if (event == TDEHardwareEvent::HardwareListModified) {
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->dev));
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
TDENetworkConnectionManager* deviceConnMan = (dev)?dev->connectionManager():NULL;
// 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)));
// force status update to ensure correct icon is shown on startup
if ((dev) && (deviceConnMan)) {
slotUpdateDeviceState(deviceConnMan->deviceInformation().statusFlags, TDENetworkConnectionStatus::Invalid, dev->macAddress());
}
}
}

Loading…
Cancel
Save