@ -191,7 +191,6 @@ void Tray::slotOnlineMode()
void Tray : : contextMenuAboutToShow ( KPopupMenu * menu )
void Tray : : contextMenuAboutToShow ( KPopupMenu * menu )
{
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
TDEGlobalNetworkManager * nm = KGlobal : : networkManager ( ) ;
TDEGlobalNetworkManager * nm = KGlobal : : networkManager ( ) ;
nm - > loadConnectionInformation ( ) ;
nm - > loadConnectionInformation ( ) ;
@ -388,8 +387,6 @@ void Tray::slotAddDeviceTrayComponent(TQString dev)
void Tray : : slotRemoveDeviceTrayComponent ( TQString dev )
void Tray : : slotRemoveDeviceTrayComponent ( TQString dev )
{
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
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 * dev_comp = dynamic_cast < DeviceTrayComponent * > ( * it ) ;
DeviceTrayComponent * dev_comp = dynamic_cast < DeviceTrayComponent * > ( * it ) ;
@ -430,8 +427,6 @@ void Tray::createDeviceTrayComponent(TQString dev)
{
{
bool trayExists = false ;
bool trayExists = false ;
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
// check if we have already a trayicon for this device
// check if we have already a trayicon for this device
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 )
{
{
@ -477,9 +472,6 @@ void Tray::createDeviceTrayComponent(TQString dev)
void Tray : : updateDeviceTrays ( )
void Tray : : updateDeviceTrays ( )
{
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
if ( ! hwdevices ) return ;
// create one tray-icon for each device
// create one tray-icon for each device
TDEGenericHardwareList devices = hwdevices - > listByDeviceClass ( TDEGenericDeviceType : : Network ) ;
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 )
void Tray : : trayComponentNeedsCenterStage ( TrayComponent * component , bool needsIt )
{
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
TDEGlobalNetworkManager * nm = KGlobal : : networkManager ( ) ;
if ( ! hwdevices ) return ;
DeviceTrayComponent * dtc = dynamic_cast < DeviceTrayComponent * > ( component ) ;
DeviceTrayComponent * dtc = dynamic_cast < DeviceTrayComponent * > ( component ) ;
if ( dtc ) {
if ( dtc ) {
@ -535,35 +565,29 @@ void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt)
TDENetworkDevice * device = dtc_comp_dev ;
TDENetworkDevice * device = dtc_comp_dev ;
if ( needsIt ) {
if ( needsIt ) {
if ( d - > foregroundTrayComponent ) {
if ( d - > foregroundTrayComponent ) {
TDENetworkDevice * foreground_tray_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( d - > foregroundTrayComponent - > device ( ) ) ) ;
disconnectTrayDeviceManager ( ) ;
disconnect ( foreground_tray_dev , TQT_SIGNAL ( StateChanged ( NMDeviceState ) ) , this , 0 ) ;
}
}
d - > foregroundTrayComponent = dtc ;
d - > foregroundTrayComponent = dtc ;
connect ( device , TQT_SIGNAL ( StateChanged ( NMDeviceState ) ) , TQT_SLOT ( slotUpdateDeviceState ( NMDeviceState ) ) ) ;
connectTrayDeviceManager ( ) ;
} else {
}
disconnect ( device , TQT_SIGNAL ( StateChanged ( NMDeviceState ) ) , this , 0 ) ;
else {
disconnectTrayDeviceManager ( ) ;
// use active default
// use active default
#if 0
TQStringList defaultDevices = nm - > defaultNetworkDevices ( ) ;
// FIXME
if ( defaultDevices . count ( ) > 0 ) {
// The TDE network backend has no concept of a default device
// Should it?
device = nm - > getDefaultDevice ( ) ;
if ( device ) {
// identify the new foreground
// 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 ) ;
DeviceTrayComponent * newDtc = dynamic_cast < DeviceTrayComponent * > ( * it ) ;
if ( newDtc & & newDtc - > device ( ) = = de vice ) {
if ( newDtc & & newDtc - > device ( ) = = defaultDevices [ 0 ] ) {
d - > foregroundTrayComponent = newDtc ;
d - > foregroundTrayComponent = newDtc ;
break ;
break ;
}
}
}
}
kdDebug ( ) < < " Device " < < dtc_comp_dev - > deviceNode ( ) < < " background, new foreground device: " < < device - > deviceNode ( ) < < endl ;
kdDebug ( ) < < " Device " < < dtc_comp_dev - > deviceNode ( ) < < " background, new foreground device: " < < device - > deviceNode ( ) < < endl ;
connect ( device , TQT_SIGNAL ( StateChanged ( NMDeviceState ) ) ,
connectTrayDeviceManager ( ) ;
TQT_SLOT ( slotUpdateDeviceState ( NMDeviceState ) ) ) ;
updateTrayDeviceManagerState ( ) ;
slotUpdateDeviceState ( device - > getState ( ) ) ;
}
}
# endif
}
}
}
}
}
}
@ -573,17 +597,16 @@ void Tray::slotUpdateDeviceState()
// FIXME
// FIXME
}
}
void Tray : : slotUpdateDeviceState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state)
void Tray : : slotUpdateDeviceState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus newState, TDENetworkConnectionStatu s: : TDENetworkConnectionStatus prevS tate, TQString hwAddress )
{
{
updateTrayIcon ( state ) ;
printf ( " Device state: %d \n \r " , newState ) ;
updateActiveConnection ( state ) ;
updateTrayIcon ( newState ) ;
updateActiveConnection ( newState ) ;
}
}
void Tray : : trayUiChanged ( )
void Tray : : trayUiChanged ( )
{
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
if ( ! hwdevices ) return ;
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
if ( dtc ) {
if ( dtc ) {
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dtc - > device ( ) ) ) ;
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dtc - > device ( ) ) ) ;
@ -591,6 +614,7 @@ void Tray::trayUiChanged()
updateTrayIcon ( deviceConnMan - > deviceInformation ( ) . statusFlags ) ;
updateTrayIcon ( deviceConnMan - > deviceInformation ( ) . statusFlags ) ;
}
}
}
}
void Tray : : updateTrayIcon ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
void Tray : : updateTrayIcon ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
{
{
// Get all active connections
// Get all active connections
@ -624,33 +648,37 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
// stop the old movie to avoid unnecessary wakups
// stop the old movie to avoid unnecessary wakups
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
if ( movie ( ) )
if ( movie ( ) ) {
movie ( ) - > pause ( ) ;
movie ( ) - > pause ( ) ;
}
if ( ( dtc ) & & ( found_any_active_connection = = 1 ) ) {
if ( ( dtc ) & & ( found_any_active_connection = = 1 ) ) {
if ( ! dtc - > movieForState ( state ) . isNull ( ) )
if ( ! dtc - > movieForState ( state ) . isNull ( ) )
{
{
// animation desired
// animation desired
int frame = - 1 ;
int frame = - 1 ;
if ( movie ( ) )
if ( movie ( ) ) {
frame = movie ( ) - > frameNumber ( ) ;
frame = movie ( ) - > frameNumber ( ) ;
}
// set the movie
// set the movie
setMovie ( dtc - > movieForState ( state ) ) ;
setMovie ( dtc - > movieForState ( state ) ) ;
// start at the same frame as the movie before
// start at the same frame as the movie before
if ( frame > 0 )
if ( frame > 0 ) {
movie ( ) - > step ( frame ) ;
movie ( ) - > step ( frame ) ;
}
// start the animation
// start the animation
movie ( ) - > unpause ( ) ;
movie ( ) - > unpause ( ) ;
}
}
else if ( ! dtc - > pixmapForState ( state ) . isNull ( ) )
else if ( ! dtc - > pixmapForState ( state ) . isNull ( ) ) {
setPixmap ( dtc - > pixmapForState ( state ) ) ;
setPixmap ( dtc - > pixmapForState ( state ) ) ;
else
}
else {
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
}
}
}
else {
else {
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
}
}
@ -705,8 +733,36 @@ void Tray::slotEditNotifications()
KNotifyDialog : : configure ( this ) ;
KNotifyDialog : : configure ( this ) ;
}
}
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 ( )
Tray : : Tray ( ) : KSystemTray ( )
{
{
hwdevices = KGlobal : : hardwareDevices ( ) ;
d = new TrayPrivate ( TQT_TQOBJECT ( this ) ) ;
d = new TrayPrivate ( TQT_TQOBJECT ( this ) ) ;
connect ( & d - > signalMapper , TQT_SIGNAL ( mapped ( int ) ) , this , TQT_SLOT ( slotDeactivateConnection ( int ) ) ) ;
connect ( & d - > signalMapper , TQT_SIGNAL ( mapped ( int ) ) , this , TQT_SLOT ( slotDeactivateConnection ( int ) ) ) ;
@ -756,16 +812,12 @@ Tray::Tray () : KSystemTray ()
connect ( KGlobal : : networkManager ( ) , TQT_SIGNAL ( networkConnectionStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) , this , TQT_SLOT ( slotStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) ) ;
connect ( KGlobal : : networkManager ( ) , TQT_SIGNAL ( networkConnectionStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) , this , TQT_SLOT ( slotStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) ) ;
// get notified about new/removed devices
// get notified about new/removed devices
// FIXME
connect ( hwdevices , TQT_SIGNAL ( hardwareAdded ( TDEGenericDevice * ) ) , this , TQT_SLOT ( slotGenericDeviceAdded ( TDEGenericDevice * ) ) ) ;
// DeviceStore* store = DeviceStore::getInstance();
connect ( hwdevices , TQT_SIGNAL ( hardwareRemoved ( TDEGenericDevice * ) ) , this , TQT_SLOT ( slotGenericDeviceRemoved ( TDEGenericDevice * ) ) ) ;
// connect(store, TQT_SIGNAL(DeviceStoreChanged()), this, TQT_SLOT(updateDeviceTrays()));
connect ( hwdevices , TQT_SIGNAL ( hardwareEvent ( TDEHardwareEvent : : TDEHardwareEvent , TQString ) ) , this , TQT_SLOT ( slotGenericHardwareEvent ( TDEHardwareEvent : : TDEHardwareEvent , TQString ) ) ) ;
// connect(store, TQT_SIGNAL(DeviceAdded(TDENetworkDevice*)), this, TQT_SLOT(slotAddDeviceTrayComponent(TDENetworkDevice*)));
// connect(store, TQT_SIGNAL(DeviceRemoved(TDENetworkDevice*)), this, TQT_SLOT(slotRemoveDeviceTrayComponent(TDENetworkDevice*)));
// Notifications
// Notifications
connect ( KGlobal : : networkManager ( ) , TQT_SIGNAL ( networkConnectionStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) , this , TQT_SLOT ( slotStateChangedNotify ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags ) ) ) ;
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
// initial setup of the device-trays