/*
Copyright 2008 Will Stephenson < wstephenson @ kde . org >
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation ; either version 2 of
the License or ( at your option ) version 3 or any later version
accepted by the membership of KDE e . V . ( or its successor approved
by the membership of KDE e . V . ) , which shall act as a proxy
defined in Section 14 of version 3 of the license .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "devicetraycomponent.h"
# include <kiconloader.h>
# include <klocale.h>
# include <ksystemtray.h>
TQString DeviceTrayComponent : : pixmapForConnState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state ) {
TDENetworkConnectionStatus : : TDENetworkConnectionStatus flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) 0x80000000 ;
while ( flag > 0 ) {
if ( state & flag ) {
if ( m_pixmaps . contains ( flag ) ) {
return m_pixmaps [ flag ] ;
}
}
flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) ( flag > > 1 ) ;
}
return TQString : : null ;
}
TQString DeviceTrayComponent : : movieForConnState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state ) {
TDENetworkConnectionStatus : : TDENetworkConnectionStatus flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) 0x80000000 ;
while ( flag > 0 ) {
if ( state & flag ) {
if ( m_movies . contains ( flag ) ) {
return m_movies [ flag ] ;
}
}
flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) ( flag > > 1 ) ;
}
return TQString : : null ;
}
TQString DeviceTrayComponent : : tooltipForConnState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state ) {
TDENetworkConnectionStatus : : TDENetworkConnectionStatus flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) 0x80000000 ;
while ( flag > 0 ) {
if ( state & flag ) {
if ( m_tooltips . contains ( flag ) ) {
return m_tooltips [ flag ] ;
}
}
flag = ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) ( flag > > 1 ) ;
}
return TQString : : null ;
}
DeviceTrayComponent : : DeviceTrayComponent ( TQString device , KSystemTray * parent , const char * name )
: TrayComponent ( parent , name ) , m_device ( device )
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
TDENetworkDevice * dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( m_device ) ) ;
TDENetworkConnectionManager * deviceConnMan = dev - > connectionManager ( ) ;
// TDENM FIXME
// This TQt connection will need to be re-established whenever the device list changes, e.g. after a call to TDEHardwareDevices::queryHardwareInformation()
// Therefore, this class should listen to hardwareEvent(TDEHardwareEvent::TDEHardwareEvent, TQString) and reload devices if TDEHardwareEvent::HardwareListModified is passed
connect ( deviceConnMan , TQT_SIGNAL ( StateChanged ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) ) , TQT_SLOT ( deviceStateChanged ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus ) ) ) ;
m_pixmaps [ TDENetworkConnectionStatus : : Invalid ] = " nm_no_connection " ;
m_pixmaps [ TDENetworkConnectionStatus : : UnManaged ] = " nm_no_connection " ;
m_pixmaps [ TDENetworkConnectionStatus : : LinkUnavailable ] = " nm_no_connection " ;
m_pixmaps [ TDENetworkConnectionStatus : : Disconnected ] = " nm_no_connection " ;
m_pixmaps [ TDENetworkConnectionStatus : : Connected ] = " ok " ;
m_pixmaps [ TDENetworkConnectionStatus : : Failed ] = " nm_no_connection " ;
m_movies [ TDENetworkConnectionStatus : : EstablishingLink ] = " nm_stage01_connecting " ;
m_movies [ TDENetworkConnectionStatus : : ConfiguringProtocols ] = " nm_stage02_connecting " ;
m_movies [ TDENetworkConnectionStatus : : VerifyingProtocols ] = " nm_stage03_connecting " ;
m_movies [ TDENetworkConnectionStatus : : NeedAuthorization ] = m_movies [ TDENetworkConnectionStatus : : ConfiguringProtocols ] ;
m_tooltips [ TDENetworkConnectionStatus : : Invalid ] = i18n ( " Unknown " ) ;
m_tooltips [ TDENetworkConnectionStatus : : LinkUnavailable ] = i18n ( " Down " ) ;
m_tooltips [ TDENetworkConnectionStatus : : UnManaged ] = i18n ( " Unmanaged " ) ;
m_tooltips [ TDENetworkConnectionStatus : : Disconnected ] = i18n ( " Disconnected " ) ;
m_tooltips [ TDENetworkConnectionStatus : : EstablishingLink ] = i18n ( " Preparing " ) ;
m_tooltips [ TDENetworkConnectionStatus : : ConfiguringProtocols ] = i18n ( " Configuration " ) ;
m_tooltips [ TDENetworkConnectionStatus : : NeedAuthorization ] = i18n ( " Awaiting authentication " ) ;
m_tooltips [ TDENetworkConnectionStatus : : VerifyingProtocols ] = i18n ( " IP configuration " ) ;
m_tooltips [ TDENetworkConnectionStatus : : Connected ] = i18n ( " Activated " ) ;
m_tooltips [ TDENetworkConnectionStatus : : Failed ] = i18n ( " Failed " ) ;
}
DeviceTrayComponent : : ~ DeviceTrayComponent ( )
{
}
TQString DeviceTrayComponent : : device ( ) const
{
return m_device ;
}
TQStringList DeviceTrayComponent : : getToolTipText ( )
{
TDEHardwareDevices * hwdevices = KGlobal : : hardwareDevices ( ) ;
TDENetworkDevice * dev = dynamic_cast < TDENetworkDevice * > ( hwdevices - > findByUniqueID ( m_device ) ) ;
TQStringList list ;
TDENetworkConnectionManager * deviceConnMan = dev - > connectionManager ( ) ;
TDENetworkConnectionStatus : : TDENetworkConnectionStatus state = deviceConnMan - > deviceInformation ( ) . statusFlags ;
if ( tooltipForConnState ( state ) ! = " " ) {
list . append ( i18n ( " Device: %1 " ) . arg ( dev - > deviceNode ( ) ) ) ;
list . append ( i18n ( " State: %1 " ) . arg ( tooltipForConnState ( state ) ) ) ;
}
return list ;
}
TQPixmap DeviceTrayComponent : : pixmapForState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
{
if ( pixmapForConnState ( state ) ! = " " ) {
return KSystemTray : : loadIcon ( pixmapForConnState ( state ) ) ;
}
else {
return TQPixmap ( ) ;
}
}
TQMovie DeviceTrayComponent : : movieForState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
{
if ( movieForConnState ( state ) ! = " " ) {
return TQMovie ( KGlobal : : iconLoader ( ) - > moviePath ( movieForConnState ( state ) , KIcon : : Panel ) ) ;
}
else {
return TQMovie ( ) ;
}
}
void DeviceTrayComponent : : setMovieForState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state , TQString movie )
{
m_movies [ state ] = movie ;
}
void DeviceTrayComponent : : setPixmapForState ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state , TQString pixmap )
{
m_pixmaps [ state ] = pixmap ;
}
void DeviceTrayComponent : : deviceStateChanged ( TDENetworkConnectionStatus : : TDENetworkConnectionStatus state )
{
// TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
// TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(m_device));
//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 ( state ) {
case TDENetworkConnectionStatus : : EstablishingLink :
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 ;
}
}
# include "devicetraycomponent.moc"