@ -2,6 +2,7 @@
*
* tdenetman - tray . cpp - A NetworkManager frontend for TDE
*
* Copyright ( C ) 2012 Timothy Pearson < kb9vqf @ pearsoncomputing . net >
* Copyright ( C ) 2005 , 2006 Novell , Inc .
*
* Author : Timo Hoenig < thoenig @ suse . de > , < thoenig @ nouse . net >
@ -144,7 +145,7 @@ class TrayPrivate
TQValueList < TrayComponent * > trayComponents ;
DeviceTrayComponent * foregroundTrayComponent ;
TQSignalMapper signalMapper ;
TQMap < int , T DENetworkConnection* > act_conn_map ;
TQMap < int , T QString > act_conn_map ;
int current_idx ;
} ;
@ -198,7 +199,7 @@ void Tray::slotOnlineMode()
void Tray : : slotNewVPNConnection ( )
{
printf( " Creating new VPN connection \n \r " ) ;
kdDebug( ) < < k_funcinfo < < " Creating new VPN connection " ;
// create a new VPN connection
TDEVPNConnection * conn = new TDEVPNConnection ( ) ;
@ -209,7 +210,7 @@ void Tray::slotNewVPNConnection()
void Tray : : slotVPNBannerShow ( const TQString & vpnbanner )
{
printf( " VPN banner: %s \n \r " , vpnbanner . ascii ( ) ) ;
kdDebug( ) < < k_funcinfo < < " VPN banner: " < < vpnbanner ;
KNotifyClient : : event ( winId ( ) , " knm-nm-vpn-banner " , vpnbanner ) ;
}
@ -313,7 +314,7 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu)
deviceNewConnAction = new KAction ( actionText , 0 , & d - > signalMapper , TQT_SLOT ( map ( ) ) , actionCollection ( ) , actionName ) ;
}
d - > signalMapper . setMapping ( deviceNewConnAction , d - > current_idx ) ;
d - > act_conn_map . insert ( d - > current_idx , conn ) ;
d - > act_conn_map . insert ( d - > current_idx , conn - > UUID ) ;
d - > current_idx + + ;
disableStuffActionMenu - > insert ( deviceNewConnAction ) ;
}
@ -364,23 +365,29 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu)
}
void
Tray : : s lotStateChanged( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags newState , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags prevS tate)
Tray : : s etBaseStateIcon( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags nm_s tate)
{
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags nm_state = newState ;
// change tray icon according to NM's state
if ( ( nm_state & TDENetworkGlobalManagerFlags : : Unknown )
if ( ( nm_state = = TDENetworkGlobalManagerFlags : : Unknown )
| | ( nm_state & TDENetworkGlobalManagerFlags : : Sleeping )
| | ( nm_state & TDENetworkGlobalManagerFlags : : EstablishingLink )
| | ( nm_state & TDENetworkGlobalManagerFlags : : Disconnected )
| | ( nm_state & TDENetworkGlobalManagerFlags : : BackendUnavailable ) ) {
setPixmap ( loadIcon ( " tdenetworkmanager_disabled " ) ) ;
setPixmap ( m_pixmapCache[ " tdenetworkmanager_disabled " ] ) ;
}
else if ( nm_state & TDENetworkGlobalManagerFlags : : Connected ) {
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
setPixmap ( m_pixmapCache[ " tdenetworkmanager " ] ) ;
}
}
printf ( " NM state: 0x%08x \n \r " , nm_state ) ;
void
Tray : : slotStateChanged ( TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags newState , TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags prevState )
{
setBaseStateIcon ( newState ) ;
# ifdef DEBUG_STATE
printf ( " NM state: 0x%08x \n \r " , newState ) ;
# endif // DEBUG_STATE
showActiveDeviceTray ( ) ;
}
@ -574,10 +581,10 @@ void Tray::mousePressEvent( TQMouseEvent *e )
void Tray : : slotDeactivateConnection ( int index )
{
TDENetworkConnection * conn = d - > act_conn_map [ index ] ;
TDEGlobalNetworkManager * nm = KGlobal : : networkManager ( ) ;
if ( ! nm ) return ;
TDENetworkConnection * conn = nm - > findConnectionByUUID ( d - > act_conn_map [ index ] ) ;
if ( conn ) {
nm - > deactivateConnection ( conn - > UUID ) ;
}
@ -589,7 +596,7 @@ void Tray::connectTrayDeviceManager() {
if ( foreground_tray_dev ) {
TDENetworkConnectionManager * deviceConnMan = foreground_tray_dev - > connectionManager ( ) ;
if ( deviceConnMan ) {
slotUpdateDeviceState ( deviceConnMan - > device Information( ) . statusFlags , TDENetworkConnectionStatus : : Invalid , TQString ( ) ) ;
slotUpdateDeviceState ( deviceConnMan - > device Status( ) . statusFlags , d - > foregroundTrayComponent - > lastKnownState , TQString ( ) ) ;
connect ( deviceConnMan , TQT_SIGNAL ( networkDeviceStateChanged ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TQString ) ) , this , TQT_SLOT ( slotUpdateDeviceState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TQString ) ) ) ;
}
}
@ -602,7 +609,7 @@ void Tray::disconnectTrayDeviceManager() {
if ( foreground_tray_dev ) {
TDENetworkConnectionManager * deviceConnMan = foreground_tray_dev - > connectionManager ( ) ;
if ( deviceConnMan ) {
slotUpdateDeviceState ( deviceConnMan - > device Information( ) . statusFlags , TDENetworkConnectionStatus : : Invalid , TQString ( ) ) ;
slotUpdateDeviceState ( deviceConnMan - > device Status( ) . statusFlags , d - > foregroundTrayComponent - > lastKnownState , TQString ( ) ) ;
disconnect ( deviceConnMan , TQT_SIGNAL ( networkDeviceStateChanged ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TDENetworkConnectionStatus : : TDENetworkConnectionStatus , TQString ) ) , this , 0 ) ;
}
}
@ -615,7 +622,7 @@ void Tray::updateTrayDeviceManagerState() {
if ( foreground_tray_dev ) {
TDENetworkConnectionManager * deviceConnMan = foreground_tray_dev - > connectionManager ( ) ;
if ( deviceConnMan ) {
slotUpdateDeviceState ( deviceConnMan - > device Information( ) . statusFlags , TDENetworkConnectionStatus : : Invalid , TQString ( ) ) ;
slotUpdateDeviceState ( deviceConnMan - > device Status( ) . statusFlags , d - > foregroundTrayComponent - > lastKnownState , TQString ( ) ) ;
}
}
}
@ -669,10 +676,18 @@ void Tray::slotUpdateDeviceState()
void Tray : : slotUpdateDeviceState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus newState , TDENetworkConnectionStatus : : TDENetworkConnectionStatus prevState , TQString hwAddress )
{
printf ( " Device state: 0x%08x \n \r " , newState ) ;
# ifdef DEBUG_STATE
printf ( " Device state: 0x%08x was: 0x%08x \n \r " , newState , prevState ) ;
# endif // DEBUG_STATE
if ( newState ! = prevState ) {
if ( d - > foregroundTrayComponent ) {
d - > foregroundTrayComponent - > lastKnownState = newState ;
}
updateTrayIcon ( newState ) ;
updateActiveConnection ( newState ) ;
updateTrayIcon ( newState ) ;
updateActiveConnection ( newState ) ;
}
}
void Tray : : trayUiChanged ( )
@ -681,7 +696,7 @@ void Tray::trayUiChanged()
if ( dtc ) {
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( dtc - > device ( ) ) ) ;
TDENetworkConnectionManager * deviceConnMan = dtc_comp_dev - > connectionManager ( ) ;
updateTrayIcon ( deviceConnMan - > device Information ( ) . statusFlags ) ;
updateTrayIcon ( deviceConnMan - > device Status ( ) . statusFlags ) ;
}
}
@ -691,7 +706,7 @@ void Tray::showActiveDeviceTray() {
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 - > device Information ( ) . statusFlags ;
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > device Status ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnected )
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invalid )
@ -713,7 +728,7 @@ void Tray::showActiveDeviceTray() {
if ( newDtc ) {
TDENetworkDevice * dtc_comp_dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( newDtc - > device ( ) ) ) ;
TDENetworkConnectionManager * deviceConnMan = dtc_comp_dev - > connectionManager ( ) ;
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > device Information ( ) . statusFlags ;
TDENetworkConnectionStatus : : TDENetworkConnectionStatus statusFlags = deviceConnMan - > device Status ( ) . statusFlags ;
if ( ( statusFlags = = TDENetworkConnectionStatus : : Disconnected )
| | ( statusFlags = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( statusFlags & TDENetworkConnectionStatus : : Invalid )
@ -743,9 +758,6 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
char found_any_active_connection = 0 ;
TDEGlobalNetworkManager * nm = KGlobal : : networkManager ( ) ;
TDENetworkConnectionList * allconmap ;
if ( tdenetworkmanager_editor_dialog_count = = 0 ) nm - > loadConnectionInformation ( ) ;
// Make sure the current state will be displayed
if ( d - > foregroundTrayComponent ) {
@ -753,58 +765,29 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
if ( foreground_tray_dev ) {
TDENetworkConnectionManager * deviceConnMan = foreground_tray_dev - > connectionManager ( ) ;
if ( deviceConnMan ) {
state = deviceConnMan - > device Information ( ) . statusFlags ;
state = deviceConnMan - > device Status ( ) . statusFlags ;
}
}
}
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags globalState = nm - > backendStatus ( ) ;
// get all available VPN Connections
active_vpn = 0 ;
allconmap = nm - > connections ( ) ;
for ( TDENetworkConnectionList : : Iterator it = allconmap - > begin ( ) ; it ! = allconmap - > end ( ) ; + + it ) {
TDEVPNConnection * conn = dynamic_cast < TDEVPNConnection * > ( * it ) ;
if ( ! conn ) {
continue ;
}
TDENetworkConnectionStatus : : TDENetworkConnectionStatus connStatus = nm - > checkConnectionStatus ( conn - > UUID ) ;
if ( ( connStatus & TDENetworkConnectionStatus : : Connected )
| | ( connStatus & TDENetworkConnectionStatus : : EstablishingLink )
| | ( connStatus & TDENetworkConnectionStatus : : ConfiguringProtocols )
| | ( connStatus & TDENetworkConnectionStatus : : Reconnecting )
| | ( connStatus & TDENetworkConnectionStatus : : VerifyingProtocols )
| | ( connStatus & TDENetworkConnectionStatus : : NeedAuthorization )
| | ( connStatus & TDENetworkConnectionStatus : : DependencyWait ) ) {
// This VPN connection is active!
active_vpn = 1 ;
}
if ( ( globalState & TDENetworkGlobalManagerFlags : : VPNConnected ) | ( ( globalState & TDENetworkGlobalManagerFlags : : VPNDisconnected ) & & ( globalState & TDENetworkGlobalManagerFlags : : VPNEstablishingLink ) ) ) {
active_vpn = 1 ;
}
found_any_active_connection = 0 ;
// Get all active connections
allconmap = nm - > connections ( ) ;
for ( TDENetworkConnectionList : : Iterator it = allconmap - > begin ( ) ; it ! = allconmap - > end ( ) ; + + it ) {
TDENetworkConnection * conn = ( * it ) ;
if ( ! conn ) {
continue ;
}
TDENetworkConnectionStatus : : TDENetworkConnectionStatus status = nm - > checkConnectionStatus ( conn - > UUID ) ;
if ( ( status = = TDENetworkConnectionStatus : : Disconnected )
| | ( status = = ( TDENetworkConnectionStatus : : Disconnected | TDENetworkConnectionStatus : : LinkUnavailable ) )
| | ( status & TDENetworkConnectionStatus : : Invalid )
) {
continue ;
}
// Found an active connection
if ( ( globalState & TDENetworkGlobalManagerFlags : : Connected ) | ( ( globalState & TDENetworkGlobalManagerFlags : : Disconnected ) & & ( globalState & TDENetworkGlobalManagerFlags : : EstablishingLink ) ) ) {
found_any_active_connection = 1 ;
}
# ifdef DEBUG_STATE
// if (found_any_active_connection == 1) {
// printf("Active connection found\n\r");
// }
# endif // DEBUG_STATE
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( KGlobal : : networkManager ( ) - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : VPNMask ) ;
if ( ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNFailed ) | | ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNDisconnected ) ) {
@ -820,8 +803,8 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
if ( active_vpn = = 0 ) {
if ( ( dtc ) & & ( found_any_active_connection = = 1 ) ) {
if ( ! dtc - > movieForState ( state ) . isNull ( ) )
{
TQMovie stateMovie = dtc - > movieForState ( state ) ;
if ( ! stateMovie . isNull ( ) ) {
// animation desired
int frame = - 1 ;
if ( movie ( ) ) {
@ -829,7 +812,7 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
}
// set the movie
setMovie ( dtc- > movieForState ( state ) ) ;
setMovie ( stateMovie ) ;
// start at the same frame as the movie before
if ( frame > 0 ) {
@ -839,21 +822,26 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
// start the animation
movie ( ) - > unpause ( ) ;
}
else if ( ! dtc - > pixmapForState ( state ) . isNull ( ) ) {
setPixmap ( dtc - > pixmapForState ( state ) ) ;
}
else {
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
TQPixmap statePixmap = dtc - > pixmapForState ( state ) ;
if ( ! statePixmap . isNull ( ) ) {
setPixmap ( statePixmap ) ;
}
else {
setPixmap ( m_pixmapCache [ " tdenetworkmanager " ] ) ;
}
}
}
else {
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
set BaseStateIcon( nm - > backendStatus ( ) ) ;
}
}
else {
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags current_vpn_state = ( KGlobal : : networkManager ( ) - > backendStatus ( ) & TDENetworkGlobalManagerFlags : : VPNMask ) ;
# ifdef DEBUG_STATE
printf ( " VPN state: 0x%08x \n \r " , current_vpn_state ) ;
//printf("Activated is: %d\n\r", TDENetworkConnectionStatus::Connected);
# endif // DEBUG_STATE
// stop the old movie to avoid unnecessary wakups
DeviceTrayComponent * dtc = d - > foregroundTrayComponent ;
@ -862,7 +850,7 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
if ( dtc ) {
if ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNConnected ) {
setPixmap ( loadIcon( " nm_device_vpn " ) ) ;
setPixmap ( m_pixmapCache[ " nm_device_vpn " ] ) ;
}
if ( ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNEstablishingLink )
| | ( current_vpn_state & TDENetworkGlobalManagerFlags : : VPNNeedAuthorization )
@ -893,7 +881,9 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
}
nm_device_state_global = state ;
# ifdef DEBUG_STATE
//printf("Device state: 0x%08x\n\r", nm_device_state_global);
# endif // DEBUG_STATE
}
void Tray : : updateActiveConnection ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
@ -919,7 +909,7 @@ void Tray::slotStateChangedNotify(TDENetworkGlobalManagerFlags::TDENetworkGlobal
{
TDENetworkGlobalManagerFlags : : TDENetworkGlobalManagerFlags nm_state = newState ;
// change tray ic on according to NM's state
// popup notificati on according to NM's state
if ( nm_state & TDENetworkGlobalManagerFlags : : EstablishingLink ) {
KNotifyClient : : event ( winId ( ) , " tdenm-nm-connecting " , i18n ( " NetworkManager is connecting " ) ) ;
}
@ -975,15 +965,57 @@ void Tray::slotVPNEventHandler(TDENetworkVPNEventType::TDENetworkVPNEventType ev
}
}
TQPixmap Tray : : pixmapForName ( TQString pixmapPath )
{
if ( pixmapPath ! = " " ) {
return KSystemTray : : loadIcon ( pixmapPath ) ;
}
else {
return TQPixmap ( ) ;
}
}
TQMovie Tray : : movieForName ( TQString moviePath )
{
if ( moviePath ! = " " ) {
return TQMovie ( KGlobal : : iconLoader ( ) - > moviePath ( moviePath , KIcon : : Panel , width ( ) ) ) ;
}
else {
return TQMovie ( ) ;
}
}
void Tray : : updateGraphicsCache ( ) {
m_pixmapCache [ " tdenetworkmanager " ] = pixmapForName ( " tdenetworkmanager " ) ;
m_pixmapCache [ " tdenetworkmanager_disabled " ] = pixmapForName ( " tdenetworkmanager_disabled " ) ;
m_pixmapCache [ " nm_no_connection " ] = pixmapForName ( " nm_no_connection " ) ;
m_pixmapCache [ " nm_device_vpn " ] = pixmapForName ( " nm_device_vpn " ) ;
m_pixmapCache [ " ok " ] = pixmapForName ( " ok " ) ;
m_pixmapCache [ " nm_signal_00 " ] = pixmapForName ( " nm_signal_00 " ) ;
m_pixmapCache [ " nm_signal_25 " ] = pixmapForName ( " nm_signal_25 " ) ;
m_pixmapCache [ " nm_signal_50 " ] = pixmapForName ( " nm_signal_50 " ) ;
m_pixmapCache [ " nm_signal_75 " ] = pixmapForName ( " nm_signal_75 " ) ;
m_pixmapCache [ " nm_signal_100 " ] = pixmapForName ( " nm_signal_100 " ) ;
// FIXME
// TQMovie objects are explicitly shared
// A cache cannot be implemented until these objects support deep copy!
// m_movieCache["nm_stage01_connecting"] = movieForName("nm_stage01_connecting");
// m_movieCache["nm_stage02_connecting"] = movieForName("nm_stage02_connecting");
// m_movieCache["nm_stage03_connecting"] = movieForName("nm_stage03_connecting");
}
Tray : : Tray ( ) : KSystemTray ( )
{
hwdevices = KGlobal : : hardwareDevices ( ) ;
updateGraphicsCache ( ) ;
d = new TrayPrivate ( TQT_TQOBJECT ( this ) ) ;
connect ( & d - > signalMapper , TQT_SIGNAL ( mapped ( int ) ) , this , TQT_SLOT ( slotDeactivateConnection ( int ) ) ) ;
setPixmap ( loadIcon ( " tdenetworkmanager " ) ) ;
setPixmap ( m_pixmapCache[ " tdenetworkmanager " ] ) ;
setMouseTracking ( true ) ;
// Actions used for plugging into the menu