summaryrefslogtreecommitdiffstats
path: root/tdenetworkmanager/src/tdenetman-tray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdenetworkmanager/src/tdenetman-tray.cpp')
-rw-r--r--tdenetworkmanager/src/tdenetman-tray.cpp188
1 files changed, 120 insertions, 68 deletions
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<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
{
DeviceTrayComponent* dev_comp = dynamic_cast<DeviceTrayComponent*>(*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<TrayComponent*>::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<TDENetworkDevice*>(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<TDENetworkDevice*>(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<TDENetworkDevice*>(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<DeviceTrayComponent*>(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<TDENetworkDevice*>(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<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it)
- {
+ for (TQValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) {
DeviceTrayComponent* newDtc = dynamic_cast<DeviceTrayComponent*> (*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<TDENetworkDevice*>(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<TDENetworkDevice*>(dev);
+ if (netdev) {
+ slotAddDeviceTrayComponent(netdev->uniqueID());
+ slotDeviceAddedNotify(netdev);
+ }
+}
+
+void Tray::slotGenericDeviceRemoved(TDEGenericDevice *dev)
+{
+ TDENetworkDevice* netdev = dynamic_cast<TDENetworkDevice*>(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