src/wscout_gui_trace.hh

00001 /*
00002  * WScout - Lightweight PCAP visualizer.
00003  * Copyright (C) 2007  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 "wscout_gui_packet.hh"
00032 # include "wscout_pcap_trace.hh"
00033 
00034 namespace wscout
00035 {
00036 
00037   namespace gui
00038   {
00039 
00041     class Trace: public QAbstractScrollArea
00042     {
00043       Q_OBJECT
00044 
00046       Q_PROPERTY(int position
00047                  READ position
00048                  WRITE setPosition
00049                  RESET setPosition
00050                  DESIGNABLE false
00051                  NOTIFY positionChanged(int)
00052                  USER true)
00053 
00054       enum
00055       {
00057         set_position_update_delay               = 0,
00058 
00060         scroll_contents_by_update_delay         = 20,
00061 
00063         packet_spacing                          = 4,
00064 
00066         trace_vmargin                           = packet_spacing,
00067 
00069         trace_hmargin                           = 8
00070       };
00071 
00072     public:
00074       explicit Trace(pcap::Trace* trace = 0, QWidget* parent = 0);
00075       virtual ~Trace();
00076 
00078       void                      setTrace(pcap::Trace* trace = 0);
00079 
00081       const pcap::Trace*        trace() const;
00082 
00084       int               position() const;
00085 
00087       int               lastPosition() const;
00088 
00100       QString           positionString(int pos = -1) const;
00101 
00102     signals:
00104       void              traceChanged();
00105 
00107       void              positionChanged(int);
00108 
00109     public slots:
00111       void              setPosition(int p = 0);
00112 
00114       virtual void      update();
00115 
00116     protected:
00118 
00119       virtual void      keyPressEvent(QKeyEvent*);
00120       virtual void      mouseMoveEvent(QMouseEvent*);
00121       virtual void      mousePressEvent(QMouseEvent*);
00122       virtual void      resizeEvent(QResizeEvent*);
00123       virtual void      scrollContentsBy(int, int);
00125 
00126     private:
00127       int               packetAt(const QPoint& pos) const;
00128       void              startUpdateTimer(int ms);
00129       void              resizeView(const QSize& size,
00130                                    bool         resize_pkts,
00131                                    bool         update_if_needed);
00132 
00133       struct selection
00134       {
00135         struct range: public std::pair<int, int>
00136         {
00137           range(int, int);
00138         };
00139 
00140         void            clear();
00141         bool            contains(int) const;
00142         std::ostream&   print(std::ostream&) const;
00143         selection&      toggle(int);
00144 
00145         selection&      operator = (int);
00146         selection&      operator = (const range&);
00147 
00148       private:
00149         typedef std::list<range>                list_of_ranges;
00150         typedef list_of_ranges::iterator        iterator;
00151 
00152         void            cleanup(iterator&);
00153 
00154         list_of_ranges  ranges_;
00155       };
00156 
00157       pcap::Trace*              trace_;
00158       QWidget                   view_;
00159       int                       pos_;
00160       QTimer                    update_timer_;
00161       std::vector<Packet*>      pkts_;
00162       selection                 selection_;
00163       int                       last_selected_;
00164     };
00165 
00166   } // End of namespace gui.
00167 
00168 } // End of namespace wscout.
00169 
00170 #endif // ! WSCOUT_GUI_TRACE_HH_

Generated on Wed Sep 12 16:02:49 2007 for WScout by  doxygen 1.5.3