KNemo – network interfaces monitor for systray
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

205 lines
9.2 KiB

  1. /* This file is part of KNemo
  2. Copyright (C) 2004 Percy Leonhardt <percy@eris23.de>
  3. KNemo is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of
  6. the License, or (at your option) any later version.
  7. KNemo is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include <tqrect.h>
  17. #include <tqstring.h>
  18. #include <kdebug.h>
  19. #include <tdelocale.h>
  20. #include <tdeio/global.h>
  21. #include "data.h"
  22. #include "interface.h"
  23. #include "interfacetooltip.h"
  24. InterfaceToolTip::InterfaceToolTip( Interface* interface,
  25. TQWidget* parent )
  26. : TQToolTip( parent ),
  27. mInterface( interface )
  28. {
  29. setupToolTipArray();
  30. }
  31. InterfaceToolTip::~InterfaceToolTip()
  32. {
  33. }
  34. void InterfaceToolTip::maybeTip( const TQPoint& )
  35. {
  36. TQRect rect( parentWidget()->rect() );
  37. if ( !rect.isValid() )
  38. return;
  39. TQString tooltip;
  40. setupText( tooltip );
  41. tip( rect, tooltip );
  42. }
  43. void InterfaceToolTip::setupText( TQString& text )
  44. {
  45. int toolTipContent = mInterface->getGeneralData().toolTipContent;
  46. InterfaceData& data = mInterface->getData();
  47. text += "<table cellspacing=0 cellpadding=0 border=0>";
  48. if ( ( toolTipContent & ALIAS ) &&
  49. mInterface->getSettings().alias != TQString() )
  50. text += "<tr><th colspan=2 align=center>" + mInterface->getSettings().alias + "</th></tr>";
  51. if ( toolTipContent & INTERFACE )
  52. text += "<tr><td>" + mToolTips[0].first + "</td><td>" + mInterface->getName() + "</td></tr>";
  53. if ( data.available )
  54. {
  55. if ( toolTipContent & STATUS )
  56. text += "<tr><td>" + mToolTips[2].first + "</td><td>" + i18n( "Connection established." ) + "</td></tr>";
  57. if ( toolTipContent & UPTIME )
  58. {
  59. int upsecs = mInterface->getStartTime().secsTo( TQDateTime::currentDateTime() );
  60. int updays = upsecs / 86400; // don't use TQDateTime::daysTo() because
  61. // we only want complete days
  62. TQString uptime;
  63. if ( updays == 1 )
  64. uptime = "1 day, ";
  65. else if ( updays > 1 )
  66. uptime = TQString( "%1 days, " ).arg( updays );
  67. upsecs -= 86400 * updays; // we only want the seconds of today
  68. int hrs = upsecs / 3600;
  69. int mins = ( upsecs - hrs * 3600 ) / 60;
  70. int secs = upsecs - hrs * 3600 - mins * 60;
  71. TQString time;
  72. time.sprintf( "%02d:%02d:%02d", hrs, mins, secs );
  73. uptime += time;
  74. text += "<tr><td>" + mToolTips[3].first + "</td><td>" + uptime + "</td></tr>";
  75. }
  76. }
  77. else if ( data.existing )
  78. {
  79. if ( toolTipContent & STATUS )
  80. text += "<tr><td>" + mToolTips[2].first + "</td><td>" + i18n( "Not connected." ) + "</td></tr>";
  81. }
  82. else
  83. {
  84. if ( toolTipContent & STATUS )
  85. text += "<tr><td>" + mToolTips[2].first + "</td><td>" + i18n( "Not existing." ) + "</td></tr>";
  86. }
  87. if ( data.available )
  88. {
  89. if ( toolTipContent & IP_ADDRESS )
  90. text += "<tr><td>" + mToolTips[4].first + "</td><td>" + data.ipAddress + "</td></tr>";
  91. if ( toolTipContent & SUBNET_MASK )
  92. text += "<tr><td>" + mToolTips[5].first + "</td><td>" + data.subnetMask + "</td></tr>";
  93. if ( mInterface->getType() == Interface::ETHERNET )
  94. {
  95. if ( toolTipContent & BCAST_ADDRESS )
  96. text += "<tr><td>" + mToolTips[18].first + "</td><td>" + data.broadcastAddress + "</td></tr>";
  97. if ( toolTipContent & GATEWAY )
  98. text += "<tr><td>" + mToolTips[19].first + "</td><td>" + data.defaultGateway + "</td></tr>";
  99. if ( toolTipContent & HW_ADDRESS )
  100. text += "<tr><td>" + mToolTips[6].first + "</td><td>" + data.hwAddress + "</td></tr>";
  101. }
  102. if ( mInterface->getType() == Interface::PPP )
  103. {
  104. if ( toolTipContent & PTP_ADDRESS )
  105. text += "<tr><td>" + mToolTips[7].first + "</td><td>" + data.ptpAddress + "</td></tr>";
  106. }
  107. if ( toolTipContent & RX_PACKETS )
  108. text += "<tr><td>" + mToolTips[8].first + "</td><td>" + TQString::number( data.rxPackets ) + "</td></tr>";
  109. if ( toolTipContent & TX_PACKETS )
  110. text += "<tr><td>" + mToolTips[9].first + "</td><td>" + TQString::number( data.txPackets ) + "</td></tr>";
  111. if ( toolTipContent & RX_BYTES )
  112. text += "<tr><td>" + mToolTips[10].first + "</td><td>" + data.rxString + "</td></tr>";
  113. if ( toolTipContent & TX_BYTES )
  114. text += "<tr><td>" + mToolTips[11].first + "</td><td>" + data.txString + "</td></tr>";
  115. if ( toolTipContent & DOWNLOAD_SPEED )
  116. {
  117. unsigned long bytesPerSecond = data.incomingBytes / mInterface->getGeneralData().pollInterval;
  118. text += "<tr><td>" + mToolTips[20].first + "</td><td>" + TDEIO::convertSize( bytesPerSecond ) + i18n( "/s" ) + "</td></tr>";
  119. }
  120. if ( toolTipContent & UPLOAD_SPEED )
  121. {
  122. unsigned long bytesPerSecond = data.outgoingBytes / mInterface->getGeneralData().pollInterval;
  123. text += "<tr><td>" + mToolTips[21].first + "</td><td>" + TDEIO::convertSize( bytesPerSecond ) + i18n( "/s" ) + "</td></tr>";
  124. }
  125. }
  126. if ( data.available && data.wirelessDevice )
  127. {
  128. WirelessData& wdata = mInterface->getWirelessData();
  129. if ( toolTipContent & ESSID )
  130. text += "<tr><td>" + mToolTips[12].first + "</td><td>" + wdata.essid + "</td></tr>";
  131. if ( toolTipContent & MODE )
  132. text += "<tr><td>" + mToolTips[13].first + "</td><td>" + wdata.mode + "</td></tr>";
  133. if ( toolTipContent & FREQUENCY )
  134. text += "<tr><td>" + mToolTips[14].first + "</td><td>" + wdata.frequency + "</td></tr>";
  135. if ( toolTipContent & BIT_RATE )
  136. text += "<tr><td>" + mToolTips[15].first + "</td><td>" + wdata.bitRate + "</td></tr>";
  137. if ( toolTipContent & ACCESS_POINT )
  138. text += "<tr><td>" + mToolTips[16].first + "</td><td>" + wdata.accessPoint + "</td></tr>";
  139. if ( toolTipContent & LINK_QUALITY )
  140. text += "<tr><td>" + mToolTips[17].first + "</td><td>" + wdata.linkQuality + "</td></tr>";
  141. if ( toolTipContent & NICK_NAME )
  142. text += "<tr><td>" + mToolTips[22].first + "</td><td>" + wdata.nickName + "</td></tr>";
  143. if ( toolTipContent & ENCRYPTION )
  144. {
  145. if ( wdata.encryption == true )
  146. {
  147. text += "<tr><td>" + mToolTips[23].first + "</td><td>" + i18n( "active" ) + "</td></tr>";
  148. }
  149. else
  150. {
  151. text += "<tr><td>" + mToolTips[23].first + "</td><td>" + i18n( "off" ) + "</td></tr>";
  152. }
  153. }
  154. }
  155. text += "</table>";
  156. }
  157. void InterfaceToolTip::setupToolTipArray()
  158. {
  159. // Cannot make this data static as the i18n macro doesn't seem
  160. // to work when called to early i.e. before setting the catalogue.
  161. mToolTips[0] = TQPair<TQString, int>( i18n( "Interface" ), INTERFACE );
  162. mToolTips[1] = TQPair<TQString, int>( i18n( "Alias" ), ALIAS );
  163. mToolTips[2] = TQPair<TQString, int>( i18n( "Status" ), STATUS );
  164. mToolTips[3] = TQPair<TQString, int>( i18n( "Uptime" ), UPTIME );
  165. mToolTips[4] = TQPair<TQString, int>( i18n( "IP-Address" ), IP_ADDRESS );
  166. mToolTips[5] = TQPair<TQString, int>( i18n( "Subnet Mask" ), SUBNET_MASK );
  167. mToolTips[6] = TQPair<TQString, int>( i18n( "HW-Address" ), HW_ADDRESS );
  168. mToolTips[7] = TQPair<TQString, int>( i18n( "PtP-Address" ), PTP_ADDRESS );
  169. mToolTips[8] = TQPair<TQString, int>( i18n( "Packets Received" ), RX_PACKETS );
  170. mToolTips[9] = TQPair<TQString, int>( i18n( "Packets Sent" ), TX_PACKETS );
  171. mToolTips[10] = TQPair<TQString, int>( i18n( "Bytes Received" ), RX_BYTES );
  172. mToolTips[11] = TQPair<TQString, int>( i18n( "Bytes Sent" ), TX_BYTES );
  173. mToolTips[12] = TQPair<TQString, int>( i18n( "ESSID" ), ESSID );
  174. mToolTips[13] = TQPair<TQString, int>( i18n( "Mode" ), MODE );
  175. mToolTips[14] = TQPair<TQString, int>( i18n( "Frequency" ), FREQUENCY );
  176. mToolTips[15] = TQPair<TQString, int>( i18n( "Bit Rate" ), BIT_RATE );
  177. mToolTips[16] = TQPair<TQString, int>( i18n( "Access Point" ), ACCESS_POINT );
  178. mToolTips[17] = TQPair<TQString, int>( i18n( "Link Quality" ), LINK_QUALITY );
  179. mToolTips[18] = TQPair<TQString, int>( i18n( "Broadcast Address" ), BCAST_ADDRESS );
  180. mToolTips[19] = TQPair<TQString, int>( i18n( "Default Gateway" ), LINK_QUALITY );
  181. mToolTips[20] = TQPair<TQString, int>( i18n( "Download Speed" ), DOWNLOAD_SPEED );
  182. mToolTips[21] = TQPair<TQString, int>( i18n( "Upload Speed" ), UPLOAD_SPEED );
  183. mToolTips[22] = TQPair<TQString, int>( i18n( "Nickname" ), NICK_NAME );
  184. mToolTips[23] = TQPair<TQString, int>( i18n( "Encryption" ), ENCRYPTION );
  185. mToolTips[24] = TQPair<TQString, int>();
  186. }