@ -220,12 +220,16 @@ void Tray::contextMenuAboutToShow (TDEPopupMenu* menu)
{
TDEGlobalNetworkManager * nm = TDEGlobal : : networkManager ( ) ;
if ( tdenetworkmanager_editor_dialog_count = = 0 ) nm - > loadConnectionInformation ( ) ;
// clear menu
menu - > clear ( ) ;
if ( ! ( nm - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : BackendUnavailable ) ) {
if ( nm & & ! ( nm - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : BackendUnavailable ) )
{
if ( tdenetworkmanager_editor_dialog_count = = 0 )
{
nm - > loadConnectionInformation ( ) ;
}
// actions for each Device
for ( TQValueList < TrayComponent * > : : Iterator it = d - > trayComponents . begin ( ) ; it ! = d - > trayComponents . end ( ) ; + + it ) {
( * it ) - > addMenuItems ( menu ) ;
@ -248,26 +252,34 @@ void Tray::contextMenuAboutToShow (TDEPopupMenu* menu)
TDEAction * deviceNewConnAction = 0 ;
if ( dev_comp ) {
TDENetworkDevice * dev_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dev_comp - > device ( ) ) ) ;
TQString actionName = TQString ( " new_connection_%1 " ) . arg ( dev_comp_dev - > deviceNode ( ) ) ;
TQString menuCaption = TQString ( " %1 " ) . arg ( dev_comp_dev - > deviceNode ( ) ) ;
if ( menuCaption . contains ( " eth " , FALSE ) > 0 ) {
menuCaption = menuCaption . insert ( 0 , " Wired Connection ( " ) ;
if ( dev_comp_dev )
{
TQString actionName = TQString ( " new_connection_%1 " ) . arg ( dev_comp_dev - > deviceNode ( ) ) ;
TQString menuCaption = TQString ( " %1 " ) . arg ( dev_comp_dev - > deviceNode ( ) ) ;
if ( menuCaption . contains ( " eth " , FALSE ) > 0 )
{
menuCaption = menuCaption . insert ( 0 , " Wired Connection ( " ) ;
}
else if ( menuCaption . contains ( " wlan " , FALSE ) > 0 )
{
menuCaption = menuCaption . insert ( 0 , " Wireless Connection ( " ) ;
}
else if ( menuCaption . contains ( " pan " , FALSE ) > 0 )
{
menuCaption = menuCaption . insert ( 0 , " Private Area Connection ( " ) ;
}
else
{
menuCaption = menuCaption . insert ( 0 , " Unknown Connection ( " ) ;
}
menuCaption = menuCaption . append ( " ) " ) ;
deviceNewConnAction = actionCollection ( ) - > action ( actionName . utf8 ( ) ) ;
if ( ! deviceNewConnAction )
{
deviceNewConnAction = new TDEAction ( menuCaption , 0 , ( * it ) , TQT_SLOT ( newConnection ( ) ) , actionCollection ( ) , actionName . utf8 ( ) ) ;
}
newConnActionMenu - > insert ( deviceNewConnAction ) ;
}
else if ( menuCaption . contains ( " wlan " , FALSE ) > 0 ) {
menuCaption = menuCaption . insert ( 0 , " Wireless Connection ( " ) ;
}
else if ( menuCaption . contains ( " pan " , FALSE ) > 0 ) {
menuCaption = menuCaption . insert ( 0 , " Private Area Connection ( " ) ;
}
else {
menuCaption = menuCaption . insert ( 0 , " Unknown Connection ( " ) ;
}
menuCaption = menuCaption . append ( " ) " ) ;
deviceNewConnAction = actionCollection ( ) - > action ( actionName . utf8 ( ) ) ;
if ( ! deviceNewConnAction ) {
deviceNewConnAction = new TDEAction ( menuCaption , 0 , ( * it ) , TQT_SLOT ( newConnection ( ) ) , actionCollection ( ) , actionName . utf8 ( ) ) ;
}
newConnActionMenu - > insert ( deviceNewConnAction ) ;
}
}
// New VPN connection option
@ -277,8 +289,9 @@ void Tray::contextMenuAboutToShow (TDEPopupMenu* menu)
TQString actionName = TQString ( " new_connection_%1 " ) . arg ( " vpn " ) ;
deviceNewConnAction = new TDEAction ( menuCaption , 0 , TQT_TQOBJECT ( this ) , TQT_SLOT ( slotNewVPNConnection ( ) ) , actionCollection ( ) , actionName . utf8 ( ) ) ;
newConnActionMenu - > insert ( deviceNewConnAction ) ;
}
else if ( devices = = 1 ) {
}
else if ( devices = = 1 )
{
newConnAction = actionCollection ( ) - > action ( " new_connection " ) ;
TQT_BASE_OBJECT_NAME : : disconnect ( newConnAction , TQT_SIGNAL ( activated ( ) ) ) ;
TQT_BASE_OBJECT_NAME : : connect ( newConnAction , TQT_SIGNAL ( activated ( ) ) , d - > trayComponents [ 0 ] , TQT_SLOT ( newConnection ( ) ) ) ;
@ -490,21 +503,24 @@ void Tray::createDeviceTrayComponent(TQString dev)
{
DeviceTrayComponent * devTray = 0 ;
TDENetworkDevice * new_tray_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dev ) ) ;
TDENetworkConnectionManager * deviceConnMan = new_tray_dev - > connectionManager ( ) ;
TDENetworkConnectionManager * deviceConnMan = ( new_tray_dev ? new_tray_dev - > connectionManager ( ) : NULL ) ;
// different tray icons for different device types!
switch ( deviceConnMan - > deviceType ( ) )
if ( deviceConnMan )
{
case TDENetworkDeviceType : : WiredEthernet :
devTray = new WiredDeviceTray ( dev , this , " wired_device_tray " ) ;
break ;
case TDENetworkDeviceType : : WiFi :
devTray = new WirelessDeviceTray ( dev , this , " wireless_device_tray " ) ;
break ;
case TDENetworkDeviceType : : Modem :
devTray = new CellularDeviceTray ( dev , this , " cellular_device_tray " ) ;
break ;
default :
kdWarning ( ) < < k_funcinfo < < " UDI: " < < dev < < " has unknown devicetype: " < < deviceConnMan - > deviceType ( ) < < endl ;
switch ( deviceConnMan - > deviceType ( ) )
{
case TDENetworkDeviceType : : WiredEthernet :
devTray = new WiredDeviceTray ( dev , this , " wired_device_tray " ) ;
break ;
case TDENetworkDeviceType : : WiFi :
devTray = new WirelessDeviceTray ( dev , this , " wireless_device_tray " ) ;
break ;
case TDENetworkDeviceType : : Modem :
devTray = new CellularDeviceTray ( dev , this , " cellular_device_tray " ) ;
break ;
default :
kdWarning ( ) < < k_funcinfo < < " UDI: " < < dev < < " has unknown devicetype: " < < deviceConnMan - > deviceType ( ) < < endl ;
}
}
if ( devTray )
{
@ -637,10 +653,14 @@ void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt)
TDEGlobalNetworkManager * nm = TDEGlobal : : networkManager ( ) ;
DeviceTrayComponent * dtc = dynamic_cast < DeviceTrayComponent * > ( component ) ;
if ( dtc ) {
if ( nm & & dtc )
{
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dtc - > device ( ) ) ) ;
kdDebug ( ) < < k_funcinfo < < dtc_comp_dev - > deviceNode ( ) < < " : " < < needsIt < < endl ;
TDENetworkDevice * device = dtc_comp_dev ;
kdDebug ( )
< < k_funcinfo
< < ( dtc_comp_dev ? dtc_comp_dev - > deviceNode ( ) : TQString ( " <unknown device> " ) )
< < " : " < < needsIt
< < endl ;
if ( needsIt ) {
if ( d - > foregroundTrayComponent ) {
disconnectTrayDeviceManager ( ) ;
@ -663,8 +683,14 @@ void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt)
break ;
}
}
kdDebug ( ) < < " Device " < < dtc_comp_dev - > deviceNode ( ) < < " background, new foreground device: " < < device - > deviceNode ( ) < < endl ;
if ( d - > foregroundTrayComponent ) {
TDENetworkDevice * newDtc_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( d - > foregroundTrayComponent - > device ( ) ) ) ;
kdDebug ( )
< < " Device "
< < ( dtc_comp_dev ? dtc_comp_dev - > deviceNode ( ) : TQString ( " <unknown device> " ) )
< < " background, new foreground device: "
< < ( newDtc_dev ? newDtc_dev - > deviceNode ( ) : TQString ( " <unknown device> " ) )
< < endl ;
connectTrayDeviceManager ( ) ;
updateTrayDeviceManagerState ( ) ;
}
@ -702,26 +728,34 @@ void Tray::trayUiChanged()
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
if ( dtc ) {
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dtc - > device ( ) ) ) ;
TDENetworkConnectionManager * deviceConnMan = dtc_comp_dev - > connectionManager ( ) ;
updateTrayIcon ( deviceConnMan - > deviceStatus ( ) . statusFlags ) ;
if ( dtc_comp_dev )
{
TDENetworkConnectionManager * deviceConnMan = dtc_comp_dev - > connectionManager ( ) ;
if ( deviceConnMan )
{
updateTrayIcon ( deviceConnMan - > deviceStatus ( ) . statusFlags ) ;
}
}
}
}
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 ) {
if ( d - > foregroundTrayComponent )
{
needsNewDeviceTrayComponent = false ;
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( d - > foregroundTrayComponent - > device ( ) ) ) ;
TDENetworkConnectionManager * deviceConnMan = dtc_comp_dev - > connectionManager ( ) ;
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > deviceStatus ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnected )
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invali d)
) {
needsNewDeviceTrayComponent = true ;
}
else {
needsNewDeviceTrayComponent = false ;
TDENetworkConnectionManager * deviceConnMan = ( dtc_comp_dev ? dtc_comp_dev - > connectionManager ( ) : NULL ) ;
if ( deviceConnMan )
{
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > deviceStatus ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnecte d)
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invalid ) )
{
needsNewDeviceTrayComponent = true ;
}
}
}
@ -734,17 +768,22 @@ void Tray::showActiveDeviceTray() {
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 - > deviceStatus ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnected )
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invalid )
) {
continue ;
}
else {
d - > foregroundTrayComponent = newDtc ;
break ;
TDENetworkConnectionManager * deviceConnMan = ( dtc_comp_dev ? dtc_comp_dev - > connectionManager ( ) : NULL ) ;
if ( deviceConnMan )
{
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > deviceStatus ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnected )
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invalid )
)
{
continue ;
}
else
{
d - > foregroundTrayComponent = newDtc ;
break ;
}
}
}
}
@ -777,7 +816,7 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
}
}
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags globalState = nm - > backendStatus ( ) ;
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags globalState = ( nm ? nm - > backendStatus ( ) : TDENetworkGlobalManagerFlags : : Unknown ) ;
// get all available VPN Connections
active_vpn = 0 ;
@ -796,7 +835,7 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
// }
# endif // DEBUG_STATE
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( TDEGlobal: : networkManager ( ) - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : VPNMask ) ;
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( globalState & TDENetworkGlobalManagerFlags : : VPNMask ) ;
if ( ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNFailed ) | | ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNDisconnected ) ) {
active_vpn = 0 ;
}
@ -840,11 +879,11 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
}
}
else {
setBaseStateIcon ( nm- > backendStatus ( ) ) ;
setBaseStateIcon ( globalState ) ;
}
}
else {
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( TDEGlobal: : networkManager ( ) - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : VPNMask ) ;
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( globalState & TDENetworkGlobalManagerFlags : : VPNMask ) ;
# ifdef DEBUG_STATE
printf ( " VPN state: 0x%08x \n " , current_vpn_state ) ;
//printf("Activated is: %d\n", TDENetworkConnectionStatus::Connected);
@ -905,7 +944,7 @@ void Tray::updateActiveConnection(TDENetworkConnectionStatus::TDENetworkConnecti
void Tray : : slotDeviceAddedNotify ( TDENetworkDevice * dev )
{
kdDebug ( ) < < " Tray::slotDeviceAddedNotify " < < endl ;
if ( ! dev - > deviceNode ( ) . isEmpty ( ) ) {
if ( dev & & ! dev - > deviceNode ( ) . isEmpty ( ) ) {
KNotifyClient : : event ( winId ( ) , " tdenm-nm-device-added " , i18n ( " New network device %1 found " ) . arg ( dev - > deviceNode ( ) ) ) ;
}
}
@ -913,7 +952,7 @@ void Tray::slotDeviceAddedNotify(TDENetworkDevice* dev)
void Tray : : slotDeviceRemovedNotify ( TDENetworkDevice * dev )
{
kdDebug ( ) < < " Tray::slotDeviceRemovedNotify " < < endl ;
if ( ! dev - > deviceNode ( ) . isEmpty ( ) ) {
if ( dev & & ! dev - > deviceNode ( ) . isEmpty ( ) ) {
KNotifyClient : : event ( winId ( ) , " tdenm-nm-device-removed " , i18n ( " Network device %1 removed " ) . arg ( dev - > deviceNode ( ) ) ) ;
}
}
@ -1100,7 +1139,7 @@ Tray::Tray() : KSystemTray()
// initial setup of the device-trays
updateDeviceTrays ( ) ;
slotStateChanged ( TDEGlobal: : networkManager ( ) - > backendStatus ( ) , TDENetworkGlobalManagerFlags : : Unknown ) ;
slotStateChanged ( nm ? nm - > backendStatus ( ) : TDENetworkGlobalManagerFlags : : Unknown , TDENetworkGlobalManagerFlags : : Unknown ) ;
}
Tray : : ~ Tray ( )
@ -1109,4 +1148,3 @@ Tray::~Tray ()
}
# include "tdenetman-tray.moc"