src/wscout_gui_find_dialog.hxx

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_HXX_
00024 # define WSCOUT_GUI_FIND_DIALOG_HXX_
00025 
00026 # include <QtGui/QApplication>
00027 
00028 # include "wscout_gui_find_dialog.hh"
00029 # include "wscout_hexdump.hh"
00030 
00031 namespace wscout
00032 {
00033 
00034   namespace gui
00035   {
00036 
00037     /*-----------.
00038     | FindThread |
00039     `-----------*/
00040 
00041     inline
00042     FindThread::FindThread(QObject*                     parent,
00043                            const_iterator&              current_it,
00044                            const const_iterator&        last_it,
00045                            const std::string&           bytes,
00046                            size_t                       first,
00047                            size_t                       last):
00048       QThread (parent),
00049       current_it_ (current_it),
00050       last_it_ (last_it),
00051       first_ (first),
00052       last_ (last),
00053       canceled_ (false)
00054     {
00055       const std::string prefix = bytes.substr(0, 2);
00056       const bool                has_prefix = prefix == "0x" or prefix == "0X";
00057 
00058       bytes_ = has_prefix?
00059         unhexdump(bytes.substr(2)):
00060         bytes_type (bytes.begin(), bytes.end());
00061     }
00062 
00063     inline
00064     FindThread::~FindThread()
00065     {
00066       cancel();
00067     }
00068 
00069     inline
00070     bool
00071     FindThread::canceled() const
00072     {
00073       return canceled_;
00074     }
00075 
00076     inline
00077     void
00078     FindThread::cancel()
00079     {
00080       canceled_ = true;
00081       wait();
00082     }
00083 
00084     /*-----------.
00085     | FindDialog |
00086     `-----------*/
00087 
00088     inline
00089     void
00090     FindDialog::voidIterators()
00091     {
00092       cancelThread();
00093       first_it_ = current_it_ = last_it_ = boost::none_t ();
00094     }
00095 
00096     inline
00097     void
00098     FindDialog::setIterators(const const_iterator&      first,
00099                              const const_iterator&      last,
00100                              size_t                     last_index)
00101     {
00102       cancelThread();
00103       first_it_ = first;
00104       current_it_ = first;
00105       last_it_ = last;
00106       pbar_.setMaximum(last_index);
00107       pbar_.setValue(1);
00108     }
00109 
00110     inline
00111     void
00112     FindDialog::cancelThread()
00113     {
00114       if (threadRunning())
00115         thread_->cancel();
00116       qApp->processEvents(); // Call threadFinished().
00117     }
00118 
00119     inline
00120     bool
00121     FindDialog::threadRunning() const
00122     {
00123       return thread_.get() and not thread_->isFinished();
00124     }
00125 
00126     inline
00127     bool
00128     FindDialog::validIterators() const
00129     {
00130       return first_it_ and current_it_ and last_it_;
00131     }
00132 
00133   } // End of namespace gui.
00134 
00135 } // End of namespace wscout.
00136 
00137 #endif // ! WSCOUT_GUI_FIND_DIALOG_HXX_

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