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_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 }
00166
00167 }
00168
00169 # include "wscout_gui_find_dialog.hxx"
00170
00171 #endif // ! WSCOUT_GUI_FIND_DIALOG_HH_