src/wscout_gui_trace.hh

00001 /*
00002  * WScout - Lightweight PCAP visualizer.
00003  * Copyright (C) 2007, 2008  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
00021  */
00022 
00023 #ifndef WSCOUT_GUI_TRACE_HH_
00024 # define WSCOUT_GUI_TRACE_HH_
00025 
00026 # include <ostream>
00027 
00028 # include <QtGui/QAbstractScrollArea>
00029 # include <QtCore/QTimer>
00030 
00031 # include <wipal/pcap/descriptor.hh>
00032 
00033 namespace wscout
00034 {
00035 
00036   namespace gui
00037   {
00038 
00039     // Forward declaration.
00040     struct Packet;
00041 
00043     class Trace: public QAbstractScrollArea
00044     {
00045       Q_OBJECT
00046 
00048       Q_PROPERTY(int position
00049                  READ position
00050                  WRITE setPosition
00051                  RESET setPosition
00052                  DESIGNABLE false
00053                  NOTIFY positionChanged(int)
00054                  USER true)
00055 
00056       Q_PROPERTY(bool swapContent
00057                  READ swapContent
00058                  WRITE setSwapContent
00059                  RESET setSwapContent
00060                  DESIGNABLE false)
00061 
00062 
00063       enum
00064       {
00066         set_position_update_delay               = 0,
00067 
00069         scroll_contents_by_update_delay         = 20,
00070 
00072         packet_spacing                          = 4,
00073 
00075         trace_vmargin                           = packet_spacing,
00076 
00078         trace_hmargin                           = 8
00079       };
00080 
00081     public:
00083       explicit Trace(pcapxx::descriptor<>* trace = 0, QWidget* parent = 0);
00084 
00086       Trace(const Trace& t);
00087 
00089       virtual ~Trace();
00090 
00092       void                              setTrace(pcapxx::descriptor<>* t = 0);
00093 
00095       const pcapxx::descriptor<>*       trace() const;
00096 
00098       pcapxx::descriptor<>*             trace();
00099 
00101       int               position() const;
00102 
00104       int               lastPosition() const;
00105 
00117       QString           positionString(int pos = -1) const;
00118 
00126       bool              swapContent() const;
00127 
00129       int               lastLeftClicked() const;
00130 
00131     signals:
00133       void              traceChanged();
00134 
00136       void              positionChanged(int);
00137 
00139       void              packetLeftClicked(int);
00140 
00142       void              packetDoubleLeftClicked(int);
00143 
00144     public slots:
00146       void              setPosition(int p = 0);
00147 
00153       void              setSwapContent(bool b = false);
00154 
00156       virtual void      update();
00157 
00158     protected:
00160 
00161       virtual void      keyPressEvent(QKeyEvent*);
00162       virtual void      mouseMoveEvent(QMouseEvent*);
00163       virtual void      mousePressEvent(QMouseEvent*);
00164       virtual void      mouseDoubleClickEvent(QMouseEvent*);
00165       virtual void      resizeEvent(QResizeEvent*);
00166       virtual void      scrollContentsBy(int, int);
00168 
00169     private:
00170       int               packetAt(const QPoint& pos) const;
00171       void              startUpdateTimer(int ms);
00172       void              resizeView(const QSize& size,
00173                                    bool         resize_pkts,
00174                                    bool         update_if_needed);
00175 
00176       struct selection
00177       {
00179         struct range: public std::pair<int, int>
00180         {
00182           range(int, int);
00183         };
00184 
00185         void            clear();
00186         bool            contains(int) const;
00187         std::ostream&   print(std::ostream&) const;
00188         selection&      toggle(int);
00189 
00190         selection&      operator = (int);
00191         selection&      operator = (const range&);
00192 
00193       private:
00194         typedef std::list<range>                list_of_ranges;
00195         typedef list_of_ranges::iterator        iterator;
00196 
00197         void            cleanup(iterator&);
00198 
00199         list_of_ranges  ranges_;
00200       };
00201 
00202       pcapxx::descriptor<>*     trace_;
00203       bool                      swap_content_;
00204       QWidget                   view_;
00205       int                       pos_;
00206       QTimer                    update_timer_;
00207       std::vector<Packet*>      pkts_;
00208       selection                 selection_;
00209       int                       last_selected_;
00210       int                       last_left_clicked_;
00211     };
00212 
00213   } // End of namespace gui.
00214 
00215 } // End of namespace wscout.
00216 
00217 # include "wscout_gui_trace.hxx"
00218 
00219 #endif // ! WSCOUT_GUI_TRACE_HH_

Generated on Wed Jan 30 19:02:27 2008 for WScout by  doxygen 1.5.4