@ -36,15 +36,15 @@
# include <khelpmenu.h>
# include <kpassivepopup.h>
// Qt headers
# include < qtimer.h>
# include < qfile.h>
# include < qtooltip.h>
# include < qcursor.h>
# include < qevent.h>
# include < qfont.h>
# include < qfontmetrics.h>
# include < qpainter.h>
// T Qt headers
# include < t qtimer.h>
# include < t qfile.h>
# include < t qtooltip.h>
# include < t qcursor.h>
# include < t qevent.h>
# include < t qfont.h>
# include < t qfontmetrics.h>
# include < t qpainter.h>
// C headers
# include <cstring>
@ -63,8 +63,8 @@ extern "C" {
extern const char * programName ;
KNetStatsView : : KNetStatsView ( KNetStats * parent, const QString& interface )
: KSystemTray ( parent, 0 ) , mSysDevPath ( " /sys/class/net/ " + interface + " / " ) , mInterface ( interface ) {
KNetStatsView : : KNetStatsView ( KNetStats * tq parent, const T QString& interface )
: KSystemTray ( tq parent, 0 ) , mSysDevPath ( " /sys/class/net/ " + interface + " / " ) , mInterface ( interface ) {
mFdSock = 0 ;
mFirstUpdate = true ;
mMaxSpeedAge = 0 ;
@ -81,15 +81,15 @@ KNetStatsView::KNetStatsView(KNetStats* parent, const QString& interface)
memset ( & mDevInfo , 0 , sizeof ( mDevInfo ) ) ;
strcpy ( mDevInfo . ifr_name , mInterface . latin1 ( ) ) ;
setTextFormat ( Qt: : PlainText ) ;
mContextMenu = parent- > contextMenu ( ) ;
setTextFormat ( T Qt: : PlainText ) ;
mContextMenu = tq parent- > contextMenu ( ) ;
show ( ) ;
// Timer
mTimer = new QTimer( this , " timer " ) ;
connect ( mTimer , SIGNAL( timeout ( ) ) , this , SLOT( updateStats ( void ) ) ) ;
mTimer = new T QTimer( this , " timer " ) ;
connect ( mTimer , TQT_ SIGNAL( timeout ( ) ) , this , TQT_ SLOT( updateStats ( void ) ) ) ;
QToolTip: : add ( this , i18n ( " Monitoring %1 " ) . arg( mInterface ) ) ;
T QToolTip: : add ( this , i18n ( " Monitoring %1 " ) . tq arg( mInterface ) ) ;
setup ( ) ;
mStatistics = new Statistics ( this ) ;
}
@ -106,25 +106,25 @@ void KNetStatsView::setup() {
else if ( mOptions . mViewMode = = Icon ) {
// Load Icons
KIconLoader * loader = kapp - > iconLoader ( ) ;
mIconError = loader - > loadIcon ( " theme " + QString: : number ( mOptions . mTheme ) + " _error.png " ,
mIconError = loader - > loadIcon ( " theme " + T QString: : number ( mOptions . mTheme ) + " _error.png " ,
KIcon : : Panel , ICONSIZE ) ;
mIconNone = loader - > loadIcon ( " theme " + QString: : number ( mOptions . mTheme ) + " _none.png " ,
mIconNone = loader - > loadIcon ( " theme " + T QString: : number ( mOptions . mTheme ) + " _none.png " ,
KIcon : : Panel , ICONSIZE ) ;
mIconTx = loader - > loadIcon ( " theme " + QString: : number ( mOptions . mTheme ) + " _tx.png " ,
mIconTx = loader - > loadIcon ( " theme " + T QString: : number ( mOptions . mTheme ) + " _tx.png " ,
KIcon : : Panel , ICONSIZE ) ;
mIconRx = loader - > loadIcon ( " theme " + QString: : number ( mOptions . mTheme ) + " _rx.png " ,
mIconRx = loader - > loadIcon ( " theme " + T QString: : number ( mOptions . mTheme ) + " _rx.png " ,
KIcon : : Panel , ICONSIZE ) ;
mIconBoth = loader - > loadIcon ( " theme " + QString: : number ( mOptions . mTheme ) + " _both.png " ,
mIconBoth = loader - > loadIcon ( " theme " + T QString: : number ( mOptions . mTheme ) + " _both.png " ,
KIcon : : Panel , ICONSIZE ) ;
mCurrentIcon = & mIconNone ;
}
mTimer - > start ( mOptions . mUpdateInterval ) ;
updateStats ( ) ;
QWidget: : update ( ) ;
T QWidget: : update ( ) ;
mFirstUpdate = false ;
}
void KNetStatsView : : say ( const QString& message ) {
void KNetStatsView : : say ( const T QString& message ) {
KPassivePopup : : message ( programName , message , kapp - > miniIcon ( ) , this ) ;
}
@ -135,24 +135,24 @@ void KNetStatsView::updateViewOptions() {
void KNetStatsView : : updateStats ( ) {
FILE * flags_fp = fopen ( ( mSysDevPath + " flags " ) . latin1 ( ) , " r " ) ;
bool current Status;
bool current tq Status;
if ( ! flags_fp )
current Status = false ;
current tq Status = false ;
else {
int flags ;
fscanf ( flags_fp , " %Xu " , & flags ) ;
fclose ( flags_fp ) ;
current Status = IFF_UP & flags ;
current tq Status = IFF_UP & flags ;
}
if ( ! current Status & & mConnected ) { // interface down...
if ( ! current tq Status & & mConnected ) { // interface down...
mConnected = false ;
resetBuffers ( ) ;
QWidget: : update ( ) ;
say ( i18n ( " %1 is inactive " ) . arg( mInterface ) ) ;
} else if ( current Status & & ! mConnected ) {
T QWidget: : update ( ) ;
say ( i18n ( " %1 is inactive " ) . tq arg( mInterface ) ) ;
} else if ( current tq Status & & ! mConnected ) {
mConnected = true ;
say ( i18n ( " %1 is active " ) . arg( mInterface ) ) ;
say ( i18n ( " %1 is active " ) . tq arg( mInterface ) ) ;
}
// kernel < 2.6.9 (I think) does not have carrier info, considering carrier ever on.
@ -168,13 +168,13 @@ void KNetStatsView::updateStats() {
if ( carrierFlag = = ' 0 ' ) { // carrier down
if ( mCarrier ) {
mCarrier = false ;
QWidget: : update ( ) ;
say ( i18n ( " %1 is disconnected " ) . arg( mInterface ) ) ;
T QWidget: : update ( ) ;
say ( i18n ( " %1 is disconnected " ) . tq arg( mInterface ) ) ;
}
return ;
} else if ( ! mCarrier ) { // carrier up
mCarrier = true ;
say ( i18n ( " %1 is connected " ) . arg( mInterface ) ) ;
say ( i18n ( " %1 is connected " ) . tq arg( mInterface ) ) ;
}
unsigned int brx = readInterfaceNumValue ( " rx_bytes " ) ;
@ -213,7 +213,7 @@ void KNetStatsView::updateStats() {
}
if ( mOptions . mViewMode = = Icon ) {
QPixmap* newIcon ;
T QPixmap* newIcon ;
if ( brx = = mBRx ) {
if ( btx = = mBTx )
newIcon = & mIconNone ;
@ -228,10 +228,10 @@ void KNetStatsView::updateStats() {
if ( newIcon ! = mCurrentIcon ) {
mCurrentIcon = newIcon ;
QWidget: : update ( ) ;
T QWidget: : update ( ) ;
}
} else if ( mOptions . mViewMode = = Graphic | | ( btx ! = mBTx & & brx ! = mBRx ) )
QWidget: : update ( ) ;
T QWidget: : update ( ) ;
// Update stats
mTotalBytesRx + = brx - mBRx ;
@ -246,7 +246,7 @@ void KNetStatsView::updateStats() {
}
unsigned long KNetStatsView : : readInterfaceNumValue ( const char * name ) {
// stdio functions appear to be more fast than QFile?
// stdio functions appear to be more fast than T QFile?
FILE * fp = fopen ( ( mSysDevPath + " statistics/ " + name ) . latin1 ( ) , " r " ) ;
long retval ;
fscanf ( fp , " %lu " , & retval ) ;
@ -254,10 +254,10 @@ unsigned long KNetStatsView::readInterfaceNumValue(const char* name) {
return retval ;
}
QString KNetStatsView : : readInterfaceStringValue ( const char * name , int maxlength ) {
QFile macFile ( mSysDevPath + name ) ;
T QString KNetStatsView : : readInterfaceStringValue ( const char * name , int maxlength ) {
T QFile macFile ( mSysDevPath + name ) ;
macFile . open ( IO_ReadOnly ) ;
QString value ;
T QString value ;
macFile . readLine ( value , maxlength ) ;
return value ;
}
@ -271,8 +271,8 @@ void KNetStatsView::resetBuffers() {
memset ( mSpeedBufferPTx , 0 , sizeof ( double ) * SPEED_BUFFER_SIZE ) ;
}
void KNetStatsView : : paintEvent ( QPaintEvent* ) {
QPainter paint ( this ) ;
void KNetStatsView : : paintEvent ( T QPaintEvent* ) {
T QPainter paint ( this ) ;
switch ( mOptions . mViewMode ) {
case Icon :
if ( ! mCarrier | | ! mConnected )
@ -288,25 +288,25 @@ void KNetStatsView::paintEvent( QPaintEvent* ) {
}
}
void KNetStatsView : : drawText ( QPainter& paint ) {
void KNetStatsView : : drawText ( T QPainter& paint ) {
if ( ! mCarrier | | ! mConnected ) {
paint . drawText ( rect ( ) , Qt: : AlignCenter , " ? " ) ;
paint . drawText ( rect ( ) , T Qt: : AlignCenter , " ? " ) ;
} else {
paint . setFont ( mOptions . mTxtFont ) ;
paint . setPen ( mOptions . mTxtUplColor ) ;
paint . drawText ( rect ( ) , Qt: : AlignTop , Statistics : : byteFormat ( byteSpeedTx ( ) , " KB " , " MB " ) ) ;
paint . drawText ( rect ( ) , T Qt: : AlignTop , Statistics : : byteFormat ( byteSpeedTx ( ) , " KB " , " MB " ) ) ;
paint . setPen ( mOptions . mTxtDldColor ) ;
paint . drawText ( rect ( ) , Qt: : AlignBottom , Statistics : : byteFormat ( byteSpeedRx ( ) , " KB " , " MB " ) ) ;
paint . drawText ( rect ( ) , T Qt: : AlignBottom , Statistics : : byteFormat ( byteSpeedRx ( ) , " KB " , " MB " ) ) ;
}
}
void KNetStatsView : : drawGraphic ( QPainter& paint ) {
void KNetStatsView : : drawGraphic ( T QPainter& paint ) {
if ( ! mCarrier | | ! mConnected ) {
paint . drawText ( rect ( ) , Qt: : AlignCenter , " X " ) ;
paint . drawText ( rect ( ) , T Qt: : AlignCenter , " X " ) ;
return ;
}
QSize size = this - > size ( ) ;
T QSize size = this - > size ( ) ;
if ( ! mOptions . mChartTransparentBackground )
paint . fillRect ( 0 , 0 , size . width ( ) , size . height ( ) , mOptions . mChartBgColor ) ;
@ -339,9 +339,9 @@ void KNetStatsView::drawGraphic(QPainter& paint) {
}
}
void KNetStatsView : : mousePressEvent ( QMouseEvent* ev ) {
void KNetStatsView : : mousePressEvent ( T QMouseEvent* ev ) {
if ( ev - > button ( ) = = Qt : : RightButton )
mContextMenu - > exec ( QCursor: : pos ( ) ) ;
mContextMenu - > exec ( T QCursor: : pos ( ) ) ;
else if ( ev - > button ( ) = = Qt : : LeftButton )
if ( mStatistics - > isShown ( ) )
mStatistics - > accept ( ) ;
@ -357,7 +357,7 @@ bool KNetStatsView::openFdSocket() {
return false ;
}
QString KNetStatsView : : getIp ( ) {
T QString KNetStatsView : : getIp ( ) {
if ( mFdSock = = - 1 & & ! openFdSocket ( ) )
return " " ;
@ -366,15 +366,15 @@ QString KNetStatsView::getIp() {
return inet_ntoa ( sin . sin_addr ) ;
}
QString KNetStatsView : : getNet mask( ) {
T QString KNetStatsView : : getNet tq mask( ) {
if ( mFdSock = = - 1 & & ! openFdSocket ( ) )
return " " ;
ioctl ( mFdSock , SIOCGIFNETMASK , & mDevInfo ) ;
sockaddr_in mask = ( ( sockaddr_in & ) mDevInfo . ifr_netmask ) ;
return inet_ntoa ( mask. sin_addr ) ;
sockaddr_in tq mask = ( ( sockaddr_in & ) mDevInfo . ifr_netmask ) ;
return inet_ntoa ( tq mask. sin_addr ) ;
}
void KNetStatsView : : readOptions ( const QString& name , KNetStatsView : : Options * opts , bool defaultVisibility ) {
void KNetStatsView : : readOptions ( const T QString& name , KNetStatsView : : Options * opts , bool defaultVisibility ) {
KConfig * cfg = kapp - > config ( ) ;
KConfigGroupSaver groupSaver ( cfg , name ) ;
@ -384,17 +384,17 @@ void KNetStatsView::readOptions( const QString& name, KNetStatsView::Options* op
opts - > mMonitoring = cfg - > readBoolEntry ( " Monitoring " , defaultVisibility ) ;
// txt view
opts - > mTxtFont = cfg - > readFontEntry ( " TxtFont " ) ;
opts - > mTxtUplColor = cfg - > readColorEntry ( " TxtUplColor " , & Qt: : red ) ;
opts - > mTxtDldColor = cfg - > readColorEntry ( " TxtDldColor " , & Qt: : green ) ;
opts - > mTxtUplColor = cfg - > readColorEntry ( " TxtUplColor " , & T Qt: : red ) ;
opts - > mTxtDldColor = cfg - > readColorEntry ( " TxtDldColor " , & T Qt: : green ) ;
// IconView
int defaultTheme = 0 ;
if ( name . startsWith ( " wlan " ) )
defaultTheme = 3 ; // three... is a magic number... a magic number....
opts - > mTheme = cfg - > readNumEntry ( " Theme " , defaultTheme ) ;
// Graphic
opts - > mChartUplColor = cfg - > readColorEntry ( " ChartUplColor " , & Qt: : red ) ;
opts - > mChartDldColor = cfg - > readColorEntry ( " ChartDldColor " , & Qt: : blue ) ;
opts - > mChartBgColor = cfg - > readColorEntry ( " ChartBgColor " , & Qt: : white ) ;
opts - > mChartUplColor = cfg - > readColorEntry ( " ChartUplColor " , & T Qt: : red ) ;
opts - > mChartDldColor = cfg - > readColorEntry ( " ChartDldColor " , & T Qt: : blue ) ;
opts - > mChartBgColor = cfg - > readColorEntry ( " ChartBgColor " , & T Qt: : white ) ;
opts - > mChartTransparentBackground = cfg - > readBoolEntry ( " ChartUseTransparentBackground " , true ) ;
}