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.
 
 
 
 
 
 

245 lines
5.3 KiB

  1. /* This file is part of KNemo
  2. Copyright (C) 2004, 2006 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. #ifndef INTERFACE_H
  17. #define INTERFACE_H
  18. #include <tqobject.h>
  19. #include <tqstring.h>
  20. #include <tqdatetime.h>
  21. #include "data.h"
  22. #include "global.h"
  23. #include "interfaceicon.h"
  24. #include "interfacemonitor.h"
  25. class TQTimer;
  26. class SignalPlotter;
  27. class InterfaceStatistics;
  28. class InterfaceStatusDialog;
  29. class InterfaceStatisticsDialog;
  30. /**
  31. * This class is the central place for all things that belong to an
  32. * interface. It stores some information and knows about the interface
  33. * data, icon, monitor and settings.
  34. *
  35. * @short Central class for every interface
  36. * @author Percy Leonhardt <percy@eris23.de>
  37. */
  38. class Interface : public TQObject
  39. {
  40. Q_OBJECT
  41. public:
  42. /**
  43. * Default Constructor
  44. */
  45. Interface(TQString ifname,
  46. const GeneralData& generalData,
  47. const PlotterSettings& plotterSettings );
  48. /**
  49. * Default Destructor
  50. */
  51. virtual ~Interface();
  52. void setType( int type )
  53. {
  54. mType = type;
  55. }
  56. int getType()
  57. {
  58. return mType;
  59. }
  60. void setState( int state )
  61. {
  62. mState = state;
  63. }
  64. int getState()
  65. {
  66. return mState;
  67. }
  68. const TQDateTime& getStartTime() const
  69. {
  70. return mStartTime;
  71. }
  72. const TQString& getName() const
  73. {
  74. return mName;
  75. }
  76. InterfaceData& getData()
  77. {
  78. return mData;
  79. }
  80. InterfaceSettings& getSettings()
  81. {
  82. return mSettings;
  83. }
  84. WirelessData& getWirelessData()
  85. {
  86. return mWirelessData;
  87. }
  88. const GeneralData& getGeneralData() const
  89. {
  90. return mGeneralData;
  91. }
  92. InterfaceStatistics* getStatistics()
  93. {
  94. return mStatistics;
  95. }
  96. /**
  97. * Called from reparseConfiguration() when the user changed
  98. * the settings.
  99. */
  100. void configChanged();
  101. /**
  102. * Called from the interface updater class after new data from
  103. * 'ifconfig' has been read. This will trigger the monitor to
  104. * to look for changes in interface data or interface state.
  105. */
  106. void activateMonitor();
  107. enum InterfaceState
  108. {
  109. UNKNOWN_STATE = -1,
  110. NOT_EXISTING = 0,
  111. NOT_AVAILABLE = 1,
  112. AVAILABLE = 2,
  113. RX_TRAFFIC = 4,
  114. TX_TRAFFIC = 8
  115. };
  116. enum InterfaceType
  117. {
  118. UNKNOWN_TYPE,
  119. ETHERNET,
  120. PPP
  121. };
  122. enum IconSet
  123. {
  124. MONITOR = 0,
  125. MODEM,
  126. NETWORK,
  127. WIRELESS
  128. };
  129. public slots:
  130. /*
  131. * Called when the user left-clicks on the tray icon
  132. * Toggles the status dialog by showing it on the first click and
  133. * hiding it on the second click.
  134. */
  135. void showStatusDialog();
  136. /*
  137. * Called when the user middle-clicks on the tray icon
  138. * Toggles the signal plotter that displays the incoming and
  139. * outgoing traffic.
  140. */
  141. void showSignalPlotter( bool wasMiddleButton );
  142. /*
  143. * Called when the user selects the appropriate entry in the context menu.
  144. */
  145. void showStatisticsDialog();
  146. /*
  147. * Reset data when PPP interface is disconnected
  148. */
  149. void resetData( int state );
  150. private slots:
  151. /**
  152. * Start the uptimer when the interface is connected
  153. */
  154. void setStartTime( int );
  155. /**
  156. * Update the signal plotter with new data
  157. */
  158. void updatePlotter();
  159. /**
  160. * Configure the signal plotter with user settings
  161. */
  162. void configurePlotter();
  163. private:
  164. /**
  165. * Start the statistics and load previously saved ones
  166. */
  167. void startStatistics();
  168. /**
  169. * Store the statistics and stop collecting any further data
  170. */
  171. void stopStatistics();
  172. /**
  173. * The following function is taken from ksystemtray.cpp for
  174. * correct show, raise, focus and hide of status dialog and
  175. * signal plotter.
  176. */
  177. void activateOrHide( TQWidget* widget, bool onlyActivate = false );
  178. enum VisibleBeams
  179. {
  180. NONE = 0,
  181. INCOMING_TRAFFIC = 1,
  182. OUTGOING_TRAFFIC = 2,
  183. BOTH = 3
  184. };
  185. int mType;
  186. int mState;
  187. int mOutgoingPos;
  188. int mIncomingPos;
  189. TQString mName;
  190. TQTimer* mPlotterTimer;
  191. TQDateTime mStartTime;
  192. InterfaceIcon mIcon;
  193. InterfaceData mData;
  194. InterfaceMonitor mMonitor;
  195. InterfaceSettings mSettings;
  196. InterfaceStatistics* mStatistics;
  197. WirelessData mWirelessData;
  198. InterfaceStatusDialog* mStatusDialog;
  199. InterfaceStatisticsDialog* mStatisticsDialog;
  200. SignalPlotter* mPlotter;
  201. VisibleBeams mVisibleBeams;
  202. const GeneralData& mGeneralData;
  203. const PlotterSettings& mPlotterSettings;
  204. };
  205. #endif // INTERFACE_H