From 2ac42d4b7a4401a42bf90418c330bc23b3c5fee4 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 10 Sep 2012 00:58:52 -0500 Subject: [PATCH] Fix default device handling and clean up code --- tdenetworkmanager/src/devicetraycomponent.cpp | 58 +++--- tdenetworkmanager/src/main.cpp | 17 +- .../src/tdenetman-cellular_device_tray.cpp | 3 +- .../src/tdenetman-device_tray.cpp | 12 +- tdenetworkmanager/src/tdenetman-tray.cpp | 188 +++++++++++------- tdenetworkmanager/src/tdenetman-tray.h | 14 +- .../src/tdenetman-wired_device_tray.cpp | 4 +- .../src/tdenetman-wireless_device_tray.cpp | 46 +++-- .../src/tdenetman-wireless_menuitem.cpp | 2 + tdenetworkmanager/src/tdenetman.cpp | 9 +- 10 files changed, 223 insertions(+), 130 deletions(-) diff --git a/tdenetworkmanager/src/devicetraycomponent.cpp b/tdenetworkmanager/src/devicetraycomponent.cpp index 2381781..ede0e9f 100644 --- a/tdenetworkmanager/src/devicetraycomponent.cpp +++ b/tdenetworkmanager/src/devicetraycomponent.cpp @@ -26,39 +26,39 @@ along with this program. If not, see . TQString DeviceTrayComponent::pixmapForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (m_pixmaps.contains(flag)) { return m_pixmaps[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQString::null; } TQString DeviceTrayComponent::movieForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (m_movies.contains(flag)) { return m_movies[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQString::null; } TQString DeviceTrayComponent::tooltipForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (m_tooltips.contains(flag)) { return m_tooltips[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQString::null; } @@ -136,7 +136,13 @@ TQStringList DeviceTrayComponent::getToolTipText() TQPixmap DeviceTrayComponent::pixmapForState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { if (pixmapForConnState(state) != "") { - return KSystemTray::loadIcon(pixmapForConnState(state)); + TQString pixmapPath = pixmapForConnState(state); + if (pixmapPath != "") { + return KSystemTray::loadIcon(pixmapPath); + } + else { + return TQPixmap(); + } } else { return TQPixmap(); @@ -146,7 +152,13 @@ TQPixmap DeviceTrayComponent::pixmapForState(TDENetworkConnectionStatus::TDENetw TQMovie DeviceTrayComponent::movieForState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { if (movieForConnState(state) != "") { - return TQMovie( KGlobal::iconLoader()->moviePath(movieForConnState(state), KIcon::Panel)); + TQString moviePath = movieForConnState(state); + if (moviePath != "") { + return TQMovie(KGlobal::iconLoader()->moviePath(moviePath, KIcon::Panel)); + } + else { + return TQMovie(); + } } else { return TQMovie(); @@ -166,31 +178,31 @@ void DeviceTrayComponent::setPixmapForState(TDENetworkConnectionStatus::TDENetwo void DeviceTrayComponent::deviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress) { TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); TDENetworkDevice* dev = dynamic_cast(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()); + return; } + printf("Device tray state: %d\n\r", newState); + //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 (newState) { - case TDENetworkConnectionStatus::EstablishingLink: + if (newState & TDENetworkConnectionStatus::EstablishingLink) { + emit needsCenterStage(this, true); + } + else if (newState & TDENetworkConnectionStatus::Connected) { + if (nm->defaultNetworkDevices().contains(m_device)) { emit needsCenterStage(this, true); - break; - case TDENetworkConnectionStatus::Connected: -// if ( m_device == nm->getDefaultDevice() ) { - emit needsCenterStage(this, true); -// } - break; - case TDENetworkConnectionStatus::LinkUnavailable: - case TDENetworkConnectionStatus::Disconnected: - case TDENetworkConnectionStatus::Failed: - emit needsCenterStage(this, false); - break; - default: - break; + } + } + else if ((newState & TDENetworkConnectionStatus::LinkUnavailable) + || (newState & TDENetworkConnectionStatus::Disconnected) + || (newState & TDENetworkConnectionStatus::Failed)) { + emit needsCenterStage(this, false); } } #include "devicetraycomponent.moc" diff --git a/tdenetworkmanager/src/main.cpp b/tdenetworkmanager/src/main.cpp index f8c86cb..02cd662 100644 --- a/tdenetworkmanager/src/main.cpp +++ b/tdenetworkmanager/src/main.cpp @@ -23,6 +23,7 @@ **************************************************************************/ // TDE includes +#include #include #include #include @@ -56,10 +57,20 @@ kdemain (int argc, char* argv[]) KCmdLineArgs::init (argc, argv, &aboutData); - if (TDENetworkManager::start ()) { + if (TDENetworkManager::start()) { TDENetworkManager app; - app.disableSessionManagement (); - return app.exec (); + app.disableSessionManagement(); + + if (!KGlobal::hardwareDevices()) { + printf("[ERROR] Unable to load tdenetworkmanager due to invalid KGlobal::hardwareDevices() object\n\r"); fflush(stdout); + return -1; + } + if (!KGlobal::networkManager()) { + printf("[ERROR] Unable to load tdenetworkmanager due to invalid KGlobal::hardwareDevices() object\n\r"); fflush(stdout); + return -1; + } + + return app.exec(); } return 0; } diff --git a/tdenetworkmanager/src/tdenetman-cellular_device_tray.cpp b/tdenetworkmanager/src/tdenetman-cellular_device_tray.cpp index e43275b..86ce9ee 100644 --- a/tdenetworkmanager/src/tdenetman-cellular_device_tray.cpp +++ b/tdenetworkmanager/src/tdenetman-cellular_device_tray.cpp @@ -112,8 +112,9 @@ void CellularDeviceTray::addMenuItems(KPopupMenu* menu) // bring the device down KAction* deactivate = tray()->actionCollection()->action("deactivate_device"); - if (deactivate) + if (deactivate) { deactivate->plug(menu); + } menu->insertSeparator(); } diff --git a/tdenetworkmanager/src/tdenetman-device_tray.cpp b/tdenetworkmanager/src/tdenetman-device_tray.cpp index 798b707..6b2d3aa 100644 --- a/tdenetworkmanager/src/tdenetman-device_tray.cpp +++ b/tdenetworkmanager/src/tdenetman-device_tray.cpp @@ -95,39 +95,39 @@ class DeviceTrayPrivate TQPixmap DeviceTrayPrivate::pixmapForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (pixmaps.contains(flag)) { return pixmaps[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQPixmap(); } TQMovie DeviceTrayPrivate::movieForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (movies.contains(flag)) { return movies[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQMovie(); } TQString DeviceTrayPrivate::tooltipForConnState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { TDENetworkConnectionStatus::TDENetworkConnectionStatus flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)0x80000000; - while (flag > 0) { + while (flag != 0) { if (state & flag) { if (tooltips.contains(flag)) { return tooltips[flag]; } } - flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)(flag >> 1); + flag = (TDENetworkConnectionStatus::TDENetworkConnectionStatus)((TQ_UINT32)flag >> 1); } return TQString::null; } diff --git a/tdenetworkmanager/src/tdenetman-tray.cpp b/tdenetworkmanager/src/tdenetman-tray.cpp index 19af694..371260c 100644 --- a/tdenetworkmanager/src/tdenetman-tray.cpp +++ b/tdenetworkmanager/src/tdenetman-tray.cpp @@ -191,7 +191,6 @@ void Tray::slotOnlineMode() void Tray::contextMenuAboutToShow (KPopupMenu* menu) { - TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); TDEGlobalNetworkManager* nm = KGlobal::networkManager(); nm->loadConnectionInformation(); @@ -388,8 +387,6 @@ void Tray::slotAddDeviceTrayComponent(TQString dev) void Tray::slotRemoveDeviceTrayComponent(TQString dev) { - TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices(); - for (TQValueList::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) { DeviceTrayComponent* dev_comp = dynamic_cast(*it); @@ -430,8 +427,6 @@ void Tray::createDeviceTrayComponent(TQString dev) { bool trayExists = false; - TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices(); - // check if we have already a trayicon for this device for (TQValueList::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) { @@ -467,8 +462,8 @@ void Tray::createDeviceTrayComponent(TQString dev) } if(devTray) { - connect( devTray, TQT_SIGNAL(needsCenterStage(TrayComponent*,bool)), TQT_SLOT(trayComponentNeedsCenterStage(TrayComponent*,bool))); - connect( devTray, TQT_SIGNAL(uiUpdated()), TQT_SLOT(trayUiChanged())); + connect(devTray, TQT_SIGNAL(needsCenterStage(TrayComponent*, bool)), TQT_SLOT(trayComponentNeedsCenterStage(TrayComponent*, bool))); + connect(devTray, TQT_SIGNAL(uiUpdated()), TQT_SLOT(trayUiChanged())); d->trayComponents.append(devTray); //WILLTODO: sort } @@ -477,9 +472,6 @@ void Tray::createDeviceTrayComponent(TQString dev) void Tray::updateDeviceTrays() { - TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices(); - if (!hwdevices) return; - // create one tray-icon for each device TDEGenericHardwareList devices = hwdevices->listByDeviceClass(TDEGenericDeviceType::Network); @@ -523,10 +515,48 @@ void Tray::slotDeactivateConnection(int index) } } +void Tray::connectTrayDeviceManager() { + if (d->foregroundTrayComponent) { + TDENetworkDevice* foreground_tray_dev = dynamic_cast(hwdevices->findByUniqueID(d->foregroundTrayComponent->device())); + if (foreground_tray_dev) { + TDENetworkConnectionManager* deviceConnMan = foreground_tray_dev->connectionManager(); + if (deviceConnMan) { + slotUpdateDeviceState(deviceConnMan->deviceInformation().statusFlags, TDENetworkConnectionStatus::Invalid, TQString()); + connect(deviceConnMan, TQT_SIGNAL(networkDeviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)), this, TQT_SLOT(slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString))); + } + } + } +} + +void Tray::disconnectTrayDeviceManager() { + if (d->foregroundTrayComponent) { + TDENetworkDevice* foreground_tray_dev = dynamic_cast(hwdevices->findByUniqueID(d->foregroundTrayComponent->device())); + if (foreground_tray_dev) { + TDENetworkConnectionManager* deviceConnMan = foreground_tray_dev->connectionManager(); + if (deviceConnMan) { + slotUpdateDeviceState(deviceConnMan->deviceInformation().statusFlags, TDENetworkConnectionStatus::Invalid, TQString()); + disconnect(deviceConnMan, TQT_SIGNAL(networkDeviceStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)), this, 0); + } + } + } +} + +void Tray::updateTrayDeviceManagerState() { + if (d->foregroundTrayComponent) { + TDENetworkDevice* foreground_tray_dev = dynamic_cast(hwdevices->findByUniqueID(d->foregroundTrayComponent->device())); + if (foreground_tray_dev) { + TDENetworkConnectionManager* deviceConnMan = foreground_tray_dev->connectionManager(); + if (deviceConnMan) { + slotUpdateDeviceState(deviceConnMan->deviceInformation().statusFlags, TDENetworkConnectionStatus::Invalid, TQString()); + slotUpdateDeviceState(deviceConnMan->deviceInformation().statusFlags, TDENetworkConnectionStatus::Invalid, TQString()); + } + } + } +} + void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt) { - TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices(); - if (!hwdevices) return; + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); DeviceTrayComponent * dtc = dynamic_cast(component); if (dtc) { @@ -535,35 +565,29 @@ void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt) TDENetworkDevice * device = dtc_comp_dev; if (needsIt) { if (d->foregroundTrayComponent) { - TDENetworkDevice* foreground_tray_dev = dynamic_cast(hwdevices->findByUniqueID(d->foregroundTrayComponent->device())); - disconnect(foreground_tray_dev, TQT_SIGNAL(StateChanged(NMDeviceState)), this, 0 ); + disconnectTrayDeviceManager(); } d->foregroundTrayComponent = dtc; - connect(device, TQT_SIGNAL(StateChanged(NMDeviceState)), TQT_SLOT(slotUpdateDeviceState(NMDeviceState))); - } else { - disconnect(device, TQT_SIGNAL(StateChanged(NMDeviceState)), this, 0 ); + connectTrayDeviceManager(); + } + else { + disconnectTrayDeviceManager(); + // use active default -#if 0 - // FIXME - // The TDE network backend has no concept of a default device - // Should it? - device = nm->getDefaultDevice(); - if ( device ) { + TQStringList defaultDevices = nm->defaultNetworkDevices(); + if (defaultDevices.count() > 0) { // identify the new foreground - for (TQValueList::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) - { + for (TQValueList::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) { DeviceTrayComponent* newDtc = dynamic_cast (*it); - if ( newDtc && newDtc->device() == device ) { + if ( newDtc && newDtc->device() == defaultDevices[0] ) { d->foregroundTrayComponent = newDtc; break; } } kdDebug() << " Device " << dtc_comp_dev->deviceNode() << " background, new foreground device: " << device->deviceNode() << endl; - connect(device, TQT_SIGNAL(StateChanged(NMDeviceState)), - TQT_SLOT(slotUpdateDeviceState(NMDeviceState))); - slotUpdateDeviceState(device->getState()); + connectTrayDeviceManager(); + updateTrayDeviceManagerState(); } -#endif } } } @@ -573,17 +597,16 @@ void Tray::slotUpdateDeviceState() // FIXME } -void Tray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) +void Tray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress) { - updateTrayIcon(state); - updateActiveConnection(state); + printf("Device state: %d\n\r", newState); + + updateTrayIcon(newState); + updateActiveConnection(newState); } void Tray::trayUiChanged() { - TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices(); - if (!hwdevices) return; - DeviceTrayComponent * dtc = d->foregroundTrayComponent; if (dtc) { TDENetworkDevice* dtc_comp_dev = dynamic_cast(hwdevices->findByUniqueID(dtc->device())); @@ -591,6 +614,7 @@ void Tray::trayUiChanged() updateTrayIcon(deviceConnMan->deviceInformation().statusFlags); } } + void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { // Get all active connections @@ -624,32 +648,36 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus // stop the old movie to avoid unnecessary wakups DeviceTrayComponent * dtc = d->foregroundTrayComponent; - if (movie()) + if (movie()) { movie()->pause(); + } if ((dtc) && (found_any_active_connection == 1)) { - if (!dtc->movieForState(state).isNull()) { // animation desired int frame = -1; - if (movie()) + if (movie()) { frame = movie()->frameNumber(); + } // set the movie setMovie(dtc->movieForState(state)); // start at the same frame as the movie before - if (frame > 0) + if (frame > 0) { movie()->step(frame); + } // start the animation movie()->unpause(); } - else if (!dtc->pixmapForState(state).isNull()) + else if (!dtc->pixmapForState(state).isNull()) { setPixmap(dtc->pixmapForState(state)); - else + } + else { setPixmap(loadIcon("tdenetworkmanager")); + } } else { setPixmap(loadIcon("tdenetworkmanager")); @@ -705,8 +733,36 @@ void Tray::slotEditNotifications() KNotifyDialog::configure(this); } -Tray::Tray () : KSystemTray () +void Tray::slotGenericDeviceAdded(TDEGenericDevice *dev) { + TDENetworkDevice* netdev = dynamic_cast(dev); + if (netdev) { + slotAddDeviceTrayComponent(netdev->uniqueID()); + slotDeviceAddedNotify(netdev); + } +} + +void Tray::slotGenericDeviceRemoved(TDEGenericDevice *dev) +{ + TDENetworkDevice* netdev = dynamic_cast(dev); + if (netdev) { + slotRemoveDeviceTrayComponent(netdev->uniqueID()); + slotDeviceRemovedNotify(netdev); + } +} + +void Tray::slotGenericHardwareEvent(TDEHardwareEvent::TDEHardwareEvent event, TQString) +{ + if (event == TDEHardwareEvent::HardwareListModified) { + updateDeviceTrays(); + connectTrayDeviceManager(); + } +} + +Tray::Tray() : KSystemTray() +{ + hwdevices = KGlobal::hardwareDevices(); + d = new TrayPrivate(TQT_TQOBJECT(this)); connect(&d->signalMapper, TQT_SIGNAL(mapped(int)), this, TQT_SLOT(slotDeactivateConnection(int))); @@ -716,56 +772,52 @@ Tray::Tray () : KSystemTray () // Actions used for plugging into the menu new KAction (i18n ("Switch to offline mode"), - SmallIcon ("no", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotOfflineMode()), actionCollection (), "offline_mode"); + SmallIcon ("no", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotOfflineMode()), actionCollection (), "offline_mode"); new KAction (i18n ("Switch to online mode"), - SmallIcon ("ok", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotOnlineMode()), actionCollection (), "online_mode"); + SmallIcon ("ok", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotOnlineMode()), actionCollection (), "online_mode"); new KAction (i18n ("Disable Wireless"), - SmallIcon ("wireless_off", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotDisableWireless()), actionCollection (), "disable_wireless"); + SmallIcon ("wireless_off", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotDisableWireless()), actionCollection (), "disable_wireless"); new KAction (i18n ("Enable Wireless"), - SmallIcon ("wireless", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotEnableWireless()), actionCollection (), "enable_wireless"); + SmallIcon ("wireless", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotEnableWireless()), actionCollection (), "enable_wireless"); new KAction (i18n ("Edit Connections"), - SmallIcon ("edit", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotEditConnections()), actionCollection (), "edit_connections"); + SmallIcon ("edit", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotEditConnections()), actionCollection (), "edit_connections"); new KAction (i18n ("Configure Notifications"), - SmallIcon ("knotify", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), TQT_SLOT (slotEditNotifications()), actionCollection (), "configure_notifications"); + SmallIcon ("knotify", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), TQT_SLOT (slotEditNotifications()), actionCollection (), "configure_notifications"); // this action is only connected when the menu is shown, hence the 0 receiver new KAction (i18n ("New connection ..."), - SmallIcon ("filenew", TQIconSet::Automatic), 0, - TQT_TQOBJECT(this), 0, actionCollection (), "new_connection"); + SmallIcon ("filenew", TQIconSet::Automatic), 0, + TQT_TQOBJECT(this), 0, actionCollection (), "new_connection"); new KActionMenu (i18n ("New connection ..."), - SmallIcon ("filenew", TQIconSet::Automatic), - actionCollection(), "new_connection_menu"); + SmallIcon ("filenew", TQIconSet::Automatic), + actionCollection(), "new_connection_menu"); new KActionMenu (i18n ("Deactivate connection..."), - SmallIcon ("no", TQIconSet::Automatic), - actionCollection (), "deactivate_menu"); + SmallIcon ("no", TQIconSet::Automatic), + actionCollection (), "deactivate_menu"); // get notified when NM's state changes connect(KGlobal::networkManager(), TQT_SIGNAL(networkConnectionStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)), this, TQT_SLOT(slotStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags))); // get notified about new/removed devices - // FIXME -// DeviceStore* store = DeviceStore::getInstance(); -// connect(store, TQT_SIGNAL(DeviceStoreChanged()), this, TQT_SLOT(updateDeviceTrays())); -// connect(store, TQT_SIGNAL(DeviceAdded(TDENetworkDevice*)), this, TQT_SLOT(slotAddDeviceTrayComponent(TDENetworkDevice*))); -// connect(store, TQT_SIGNAL(DeviceRemoved(TDENetworkDevice*)), this, TQT_SLOT(slotRemoveDeviceTrayComponent(TDENetworkDevice*))); + connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(slotGenericDeviceAdded(TDEGenericDevice*))); + connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(slotGenericDeviceRemoved(TDEGenericDevice*))); + connect(hwdevices, TQT_SIGNAL(hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString)), this, TQT_SLOT(slotGenericHardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString))); // Notifications connect(KGlobal::networkManager(), TQT_SIGNAL(networkConnectionStateChanged(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags)), this, TQT_SLOT(slotStateChangedNotify(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags))); -// connect(store, TQT_SIGNAL(DeviceAdded(TDENetworkDevice*)), this, TQT_SLOT(slotDeviceAddedNotify(TDENetworkDevice*))); -// connect(store, TQT_SIGNAL(DeviceRemoved(TDENetworkDevice*)), this, TQT_SLOT(slotDeviceRemovedNotify(TDENetworkDevice*))); // initial setup of the device-trays diff --git a/tdenetworkmanager/src/tdenetman-tray.h b/tdenetworkmanager/src/tdenetman-tray.h index 10744eb..75075a8 100644 --- a/tdenetworkmanager/src/tdenetman-tray.h +++ b/tdenetworkmanager/src/tdenetman-tray.h @@ -92,9 +92,9 @@ class Tray : public KSystemTray void slotStateChangedNotify(TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags newState, TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags prevState); void slotUpdateDeviceState(); - void slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus); + void slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress); - protected slots: + protected slots: void updateDeviceTrays(); void slotAddDeviceTrayComponent(TQString); void slotRemoveDeviceTrayComponent(TQString); @@ -103,15 +103,23 @@ class Tray : public KSystemTray void trayUiChanged(); void slotEditNotifications(); + private slots: + void slotGenericDeviceAdded(TDEGenericDevice*); + void slotGenericDeviceRemoved(TDEGenericDevice*); + void slotGenericHardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString); + private: void updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void updateActiveConnection(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void mousePressEvent(TQMouseEvent *e); void createDeviceTrayComponent(TQString); void enterEvent(TQEvent*); + void connectTrayDeviceManager(); + void disconnectTrayDeviceManager(); + void updateTrayDeviceManagerState(); TrayPrivate* d; - + TDEHardwareDevices* hwdevices; }; class NewSecretsDialog : public TQDialog diff --git a/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp b/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp index 8855cd2..8a91142 100644 --- a/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp +++ b/tdenetworkmanager/src/tdenetman-wired_device_tray.cpp @@ -129,10 +129,12 @@ void WiredDeviceTray::addMenuItems(KPopupMenu* menu) // menu->insertSeparator(); menu->insertItem(SmallIcon("filenew", TQIconSet::Automatic), i18n("Create new wired connection"), this, TQT_SLOT(newConnection())); } + // bring the device down KAction* deactivate = tray()->actionCollection()->action("deactivate_device"); - if (deactivate) + if (deactivate) { deactivate->plug(menu); + } } } diff --git a/tdenetworkmanager/src/tdenetman-wireless_device_tray.cpp b/tdenetworkmanager/src/tdenetman-wireless_device_tray.cpp index b9a4623..337df5f 100644 --- a/tdenetworkmanager/src/tdenetman-wireless_device_tray.cpp +++ b/tdenetworkmanager/src/tdenetman-wireless_device_tray.cpp @@ -169,10 +169,10 @@ void WirelessDeviceTray::addWirelessNetworks(KPopupMenu* menu) } wirelessNetworkItem = new WirelessNetworkItem (menu, - d->dev, - net, - (*it)->UUID, - false); + d->dev, + net, + (*it)->UUID, + false); int id = menu->insertItem (wirelessNetworkItem, -1, -1); menu->setItemChecked(id, ((TDENetworkConnection*)(*it) == active_conn)); menu->connectItem(id, wirelessNetworkItem, TQT_SLOT(slotActivate())); @@ -198,10 +198,10 @@ void WirelessDeviceTray::addWirelessNetworks(KPopupMenu* menu) } wirelessNetworkItem = new WirelessNetworkItem (menu, - d->dev, - net, - (*it)->UUID, - false); + d->dev, + net, + (*it)->UUID, + false); int id = popup->insertItem (wirelessNetworkItem, -1, -1); popup->connectItem(id, wirelessNetworkItem, TQT_SLOT(slotActivate())); @@ -213,25 +213,25 @@ void WirelessDeviceTray::addWirelessNetworks(KPopupMenu* menu) menu->insertItem(i18n("Connect to saved network"), popup); } -// // List available unsaved networks - TQPopupMenu* newpopup = new TQPopupMenu(menu); - uint newnetworkItemsAdded = 0; - TQValueList newnets = WirelessManager::getWirelessNetworks(0, WirelessNetwork::MATCH_SSID); + // List available unsaved networks + TQPopupMenu* newpopup = new TQPopupMenu(menu); + uint newnetworkItemsAdded = 0; + TQValueList newnets = WirelessManager::getWirelessNetworks(0, WirelessNetwork::MATCH_SSID); newWirelessPopupSSIDMap.clear(); - for (TQValueList::Iterator it = newnets.begin(); it != newnets.end(); ++it) - { + for (TQValueList::Iterator it = newnets.begin(); it != newnets.end(); ++it) + { // Only display networks with no existing connnection if ( findMatchingConnection(*it, conns) != NULL) continue; - WirelessNetworkItem* wirelessNetworkItem; + WirelessNetworkItem* wirelessNetworkItem; wirelessNetworkItem = new WirelessNetworkItem (menu, - d->dev, - *it, - NULL, - false); - + d->dev, + *it, + NULL, + false); + int id = newpopup->insertItem (wirelessNetworkItem, -1, -1); newWirelessPopupSSIDMap[id] = (*it).getSsid(); newpopup->connectItem(id, this, TQT_SLOT(newConnection(int))); @@ -258,7 +258,7 @@ void WirelessDeviceTray::addMenuItems(KPopupMenu* menu) Subhead* subhead = new Subhead (menu, "subhead", TQString("Wireless Connection (%1)").arg(dev->deviceNode()), SmallIcon("wireless", TQIconSet::Automatic)); menu->insertItem (subhead, -1, -1); - // bolding subhead instead + // bolding subhead instead //menu->insertSeparator(); if (!nm->wiFiEnabled()) @@ -303,8 +303,11 @@ void WirelessDeviceTray::slotUpdateDeviceState(TDENetworkConnectionStatus::TDENe 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()); + return; } + printf("Wireless state: %d\n\r", newState); + slotCheckActiveAccessPoint(); if (newState == TDENetworkConnectionStatus::Connected) { @@ -457,6 +460,7 @@ WirelessDeviceTray::WirelessDeviceTray (TQString dev, KSystemTray * parent, cons // 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); } diff --git a/tdenetworkmanager/src/tdenetman-wireless_menuitem.cpp b/tdenetworkmanager/src/tdenetman-wireless_menuitem.cpp index f41483a..2b02796 100644 --- a/tdenetworkmanager/src/tdenetman-wireless_menuitem.cpp +++ b/tdenetworkmanager/src/tdenetman-wireless_menuitem.cpp @@ -147,6 +147,8 @@ WirelessNetworkItem::sizeHint () WirelessNetworkItem::WirelessNetworkItem (TQWidget* p, TQString dev, WirelessNetwork& net, TQString conn, bool adhoc) : NetworkMenuItem(dev, conn, 0, 0 ), TQCustomMenuItem () { + hwdevices = KGlobal::hardwareDevices(); + parent = p; _adhoc = adhoc; _net = net; diff --git a/tdenetworkmanager/src/tdenetman.cpp b/tdenetworkmanager/src/tdenetman.cpp index 19238b3..d9f2ad1 100644 --- a/tdenetworkmanager/src/tdenetman.cpp +++ b/tdenetworkmanager/src/tdenetman.cpp @@ -28,7 +28,7 @@ #include #include -// TDENM includes +// KNM includes #include "tdenetman.h" #include "tdenetman-tray.h" @@ -49,7 +49,8 @@ class TDENetworkManagerPrivate public: TDENetworkManagerPrivate() {} ~TDENetworkManagerPrivate() {} - static TDENetworkManager* _ctx; + + static TDENetworkManager* _ctx; }; TDENetworkManager* TDENetworkManagerPrivate::_ctx = NULL; @@ -68,10 +69,10 @@ TDENetworkManager::slotShutDown() void TDENetworkManager::timerEvent( TQTimerEvent *e ) { Tray* tray = Tray::getInstance(); - tray->slotUpdateDeviceState(nm_device_state_global); + tray->slotUpdateDeviceState(nm_device_state_global, TDENetworkConnectionStatus::Invalid, TQString()); } -TDENetworkManager::TDENetworkManager () : KUniqueApplication () +TDENetworkManager::TDENetworkManager() : KUniqueApplication() { d = new TDENetworkManagerPrivate(); d->_ctx = this;