src/wscout_gui_find_dialog.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_FIND_DIALOG_HH_
00024 # define WSCOUT_GUI_FIND_DIALOG_HH_
00025 
00026 # include <QtGui/QStyle>
00027 # include <QtGui/QLineEdit>
00028 # include <QtGui/QSpinBox>
00029 # include <QtGui/QPushButton>
00030 # include <QtGui/QProgressBar>
00031 # include <QtCore/QThread>
00032 
00033 # include <wipal/pcap/descriptor.hh>
00034 
00035 # include "wscout_gui_dialog.hh"
00036 
00037 namespace wscout
00038 {
00039 
00040   namespace gui
00041   {
00042 
00044     class FindThread: public QThread
00045     {
00046       Q_OBJECT
00047 
00048     public:
00049       typedef pcapxx::descriptor<>::const_iterator      const_iterator;
00050 
00051       enum
00052         {
00057           positionUpdateInterval        = 4096
00058         };
00059 
00061       FindThread(QObject*               parent,
00062                  const_iterator&        current_it,
00063                  const const_iterator&  last_it,
00064                  const std::string&     bytes,
00065                  size_t                 first,
00066                  size_t                 last);
00068       ~FindThread();
00069 
00071       void      run();
00072 
00074       bool      canceled() const;
00075 
00076     public slots:
00078       void      cancel();
00079 
00080     signals:
00082       void      positionChanged(int);
00083 
00084     private:
00085       typedef std::vector<uint8_t>      bytes_type;
00086 
00087       const_iterator&           current_it_;
00088       const const_iterator&     last_it_;
00089 
00090       bytes_type                bytes_;
00091       size_t                    first_;
00092       size_t                    last_;
00093 
00094       bool                      canceled_;
00095     };
00096 
00098     class FindDialog: public Dialog
00099     {
00100       Q_OBJECT
00101 
00102     public:
00103       typedef pcapxx::descriptor<>::const_iterator      const_iterator;
00104 
00106       FindDialog(QWidget* parent = 0);
00107 
00108       void              voidIterators();
00109       void              setIterators(const const_iterator&      first,
00110                                      const const_iterator&      last,
00111                                      size_t                     last_index);
00112 
00113 
00114     private slots:
00115       void              restartClicked();
00116       void              findNextClicked();
00117       void              cancelThread();
00118       void              threadFinished();
00119 
00120     signals:
00121       void              found(int pos);
00122       void              notFound();
00123 
00124     private:
00125       bool              threadRunning() const;
00126       bool              validIterators() const;
00127 
00128       void              setupBytesRow(QGridLayout& l);
00129       void              setupOffsetsRow(QGridLayout& l);
00130       void              setupProgressBar(QGridLayout& l);
00131       void              setupButtonsRow(QGridLayout& l, const QStyle& s);
00132 
00133     private:
00134       typedef std::auto_ptr<FindThread>         thread_ptr;
00135       typedef boost::optional<const_iterator>   optional_const_iterator;
00136 
00137       enum
00138         {
00139           first_min     = 0,
00140           first_max     = 65535,
00141           first_def     = 0,
00142 
00143           last_min      = first_min,
00144           last_max      = first_max,
00145           last_def      = first_max
00146         };
00147 
00148       thread_ptr                thread_;
00149       bool                      thread_canceled_;
00150 
00151       optional_const_iterator   first_it_;
00152       optional_const_iterator   current_it_;
00153       optional_const_iterator   last_it_;
00154 
00155       QLineEdit                 bytes_;
00156       QSpinBox                  first_;
00157       QSpinBox                  last_;
00158       QProgressBar              pbar_;
00159       QPushButton               restart_;
00160       QPushButton               cancel_;
00161       QPushButton               find_next_;
00162       QPushButton               close_;
00163     };
00164 
00165   } // End of namespace gui.
00166 
00167 } // End of namespace wscout.
00168 
00169 # include "wscout_gui_find_dialog.hxx"
00170 
00171 #endif // ! WSCOUT_GUI_FIND_DIALOG_HH_

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