/* This file is part of KNemo Copyright (C) 2004 Percy Leonhardt KNemo is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. KNemo 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include "data.h" #include "interface.h" #include "interfacetooltip.h" InterfaceToolTip::InterfaceToolTip( Interface* interface, TQWidget* parent ) : TQToolTip( parent ), mInterface( interface ) { setupToolTipArray(); } InterfaceToolTip::~InterfaceToolTip() { } void InterfaceToolTip::maybeTip( const TQPoint& ) { TQRect rect( parentWidget()->rect() ); if ( !rect.isValid() ) return; TQString tooltip; setupText( tooltip ); tip( rect, tooltip ); } void InterfaceToolTip::setupText( TQString& text ) { int toolTipContent = mInterface->getGeneralData().toolTipContent; InterfaceData& data = mInterface->getData(); text += ""; if ( ( toolTipContent & ALIAS ) && mInterface->getSettings().alias != TQString() ) text += ""; if ( toolTipContent & INTERFACE ) text += ""; if ( data.available ) { if ( toolTipContent & STATUS ) text += ""; if ( toolTipContent & UPTIME ) { int upsecs = mInterface->getStartTime().secsTo( TQDateTime::tqcurrentDateTime() ); int updays = upsecs / 86400; // don't use TQDateTime::daysTo() because // we only want complete days TQString uptime; if ( updays == 1 ) uptime = "1 day, "; else if ( updays > 1 ) uptime = TQString( "%1 days, " ).tqarg( updays ); upsecs -= 86400 * updays; // we only want the seconds of today int hrs = upsecs / 3600; int mins = ( upsecs - hrs * 3600 ) / 60; int secs = upsecs - hrs * 3600 - mins * 60; TQString time; time.sprintf( "%02d:%02d:%02d", hrs, mins, secs ); uptime += time; text += ""; } } else if ( data.existing ) { if ( toolTipContent & STATUS ) text += ""; } else { if ( toolTipContent & STATUS ) text += ""; } if ( data.available ) { if ( toolTipContent & IP_ADDRESS ) text += ""; if ( toolTipContent & SUBNET_MASK ) text += ""; if ( mInterface->getType() == Interface::ETHERNET ) { if ( toolTipContent & BCAST_ADDRESS ) text += ""; if ( toolTipContent & GATEWAY ) text += ""; if ( toolTipContent & HW_ADDRESS ) text += ""; } if ( mInterface->getType() == Interface::PPP ) { if ( toolTipContent & PTP_ADDRESS ) text += ""; } if ( toolTipContent & RX_PACKETS ) text += ""; if ( toolTipContent & TX_PACKETS ) text += ""; if ( toolTipContent & RX_BYTES ) text += ""; if ( toolTipContent & TX_BYTES ) text += ""; if ( toolTipContent & DOWNLOAD_SPEED ) { unsigned long bytesPerSecond = data.incomingBytes / mInterface->getGeneralData().pollInterval; text += ""; } if ( toolTipContent & UPLOAD_SPEED ) { unsigned long bytesPerSecond = data.outgoingBytes / mInterface->getGeneralData().pollInterval; text += ""; } } if ( data.available && data.wirelessDevice ) { WirelessData& wdata = mInterface->getWirelessData(); if ( toolTipContent & ESSID ) text += ""; if ( toolTipContent & MODE ) text += ""; if ( toolTipContent & FREQUENCY ) text += ""; if ( toolTipContent & BIT_RATE ) text += ""; if ( toolTipContent & ACCESS_POINT ) text += ""; if ( toolTipContent & LINK_TQUALITY ) text += ""; if ( toolTipContent & NICK_NAME ) text += ""; if ( toolTipContent & ENCRYPTION ) { if ( wdata.encryption == true ) { text += ""; } else { text += ""; } } } text += "
" + mInterface->getSettings().alias + "
" + mToolTips[0].first + "" + mInterface->getName() + "
" + mToolTips[2].first + "" + i18n( "Connection established." ) + "
" + mToolTips[3].first + "" + uptime + "
" + mToolTips[2].first + "" + i18n( "Not connected." ) + "
" + mToolTips[2].first + "" + i18n( "Not existing." ) + "
" + mToolTips[4].first + "" + data.ipAddress + "
" + mToolTips[5].first + "" + data.subnetMask + "
" + mToolTips[18].first + "" + data.broadcastAddress + "
" + mToolTips[19].first + "" + data.defaultGateway + "
" + mToolTips[6].first + "" + data.hwAddress + "
" + mToolTips[7].first + "" + data.ptpAddress + "
" + mToolTips[8].first + "" + TQString::number( data.rxPackets ) + "
" + mToolTips[9].first + "" + TQString::number( data.txPackets ) + "
" + mToolTips[10].first + "" + data.rxString + "
" + mToolTips[11].first + "" + data.txString + "
" + mToolTips[20].first + "" + KIO::convertSize( bytesPerSecond ) + i18n( "/s" ) + "
" + mToolTips[21].first + "" + KIO::convertSize( bytesPerSecond ) + i18n( "/s" ) + "
" + mToolTips[12].first + "" + wdata.essid + "
" + mToolTips[13].first + "" + wdata.mode + "
" + mToolTips[14].first + "" + wdata.frequency + "
" + mToolTips[15].first + "" + wdata.bitRate + "
" + mToolTips[16].first + "" + wdata.accessPoint + "
" + mToolTips[17].first + "" + wdata.linkQuality + "
" + mToolTips[22].first + "" + wdata.nickName + "
" + mToolTips[23].first + "" + i18n( "active" ) + "
" + mToolTips[23].first + "" + i18n( "off" ) + "
"; } void InterfaceToolTip::setupToolTipArray() { // Cannot make this data static as the i18n macro doesn't seem // to work when called to early i.e. before setting the catalogue. mToolTips[0] = TQPair( i18n( "Interface" ), INTERFACE ); mToolTips[1] = TQPair( i18n( "Alias" ), ALIAS ); mToolTips[2] = TQPair( i18n( "Status" ), STATUS ); mToolTips[3] = TQPair( i18n( "Uptime" ), UPTIME ); mToolTips[4] = TQPair( i18n( "IP-Address" ), IP_ADDRESS ); mToolTips[5] = TQPair( i18n( "Subnet Mask" ), SUBNET_MASK ); mToolTips[6] = TQPair( i18n( "HW-Address" ), HW_ADDRESS ); mToolTips[7] = TQPair( i18n( "PtP-Address" ), PTP_ADDRESS ); mToolTips[8] = TQPair( i18n( "Packets Received" ), RX_PACKETS ); mToolTips[9] = TQPair( i18n( "Packets Sent" ), TX_PACKETS ); mToolTips[10] = TQPair( i18n( "Bytes Received" ), RX_BYTES ); mToolTips[11] = TQPair( i18n( "Bytes Sent" ), TX_BYTES ); mToolTips[12] = TQPair( i18n( "ESSID" ), ESSID ); mToolTips[13] = TQPair( i18n( "Mode" ), MODE ); mToolTips[14] = TQPair( i18n( "Frequency" ), FREQUENCY ); mToolTips[15] = TQPair( i18n( "Bit Rate" ), BIT_RATE ); mToolTips[16] = TQPair( i18n( "Access Point" ), ACCESS_POINT ); mToolTips[17] = TQPair( i18n( "Link Quality" ), LINK_TQUALITY ); mToolTips[18] = TQPair( i18n( "Broadcast Address" ), BCAST_ADDRESS ); mToolTips[19] = TQPair( i18n( "Default Gateway" ), LINK_TQUALITY ); mToolTips[20] = TQPair( i18n( "Download Speed" ), DOWNLOAD_SPEED ); mToolTips[21] = TQPair( i18n( "Upload Speed" ), UPLOAD_SPEED ); mToolTips[22] = TQPair( i18n( "Nickname" ), NICK_NAME ); mToolTips[23] = TQPair( i18n( "Encryption" ), ENCRYPTION ); mToolTips[24] = TQPair(); }