00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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();
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 }
00134
00135 }
00136
00137 #endif // ! WSCOUT_GUI_FIND_DIALOG_HXX_