Class: Watobo::Gui::DefineScopeFrame

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
lib/watobo/gui/define_scope_frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner, opts) ⇒ DefineScopeFrame

Returns a new instance of DefineScopeFrame.



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/watobo/gui/define_scope_frame.rb', line 235

def initialize(owner, opts)
  super(owner, :opts => opts, :padding => 0)
  
 # @scope = Hash.new
 # @scope = YAML.load(YAML.dump(scope)) if scope.is_a? Hash
 @scope = YAML.load(Watobo::Scope.to_yaml)
 
  @cb_sites = Hash.new
  @edit_btns = Hash.new
  
  title = FXLabel.new(self, "Target Scope")
  info_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|FRAME_GROOVE)
  title.setFont(FXFont.new(getApp(), "helvetica", 12, FONTWEIGHT_BOLD, FONTSLANT_ITALIC, FONTENCODING_DEFAULT))
  
  scope_text =<<'EOF'
The target scopes affects primarly the 
behaviour all WATOBO scanner tools. 
Click the appropriate edit-button for more 
 detailed settings.
EOF
  btn = FXButton.new(info_frame, scope_text,
                     :opts => LAYOUT_FILL_X|LAYOUT_FIX_HEIGHT, :height => 90)
  #btn.font = @font
  #btn.backColor = FXColor::White
  btn.justify = JUSTIFY_LEFT
  
  quickFilterFrame = FXHorizontalFrame.new(self, LAYOUT_FILL_X)
  FXLabel.new(quickFilterFrame, "Filter:", nil, :opts => LAYOUT_TOP|JUSTIFY_RIGHT)
  filter_regexp = FXTextField.new(quickFilterFrame, 25, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_LEFT)
  filter_btn = FXButton.new(quickFilterFrame, "apply")

  filter_regexp.connect(SEL_COMMAND){ list_sites(filter_regexp.text.strip) }
  filter_btn.connect(SEL_COMMAND){ list_sites(filter_regexp.text.strip) }


          
  quickSelectFrame = FXHorizontalFrame.new(self, LAYOUT_FILL_X)
  @sel_all_btn = FXButton.new(quickSelectFrame, "Select All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @sel_all_btn.connect(SEL_COMMAND, method(:onSelectAll))
  
  @sel_all_btn.setFocus()
  @sel_all_btn.setDefault()
  
  @desel_all_btn = FXButton.new(quickSelectFrame, "Deselect All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @desel_all_btn.connect(SEL_COMMAND, method(:onDeselectAll)) 
  frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE, :padding => 0)
  
  sitesArea = FXScrollWindow.new(frame, SCROLLERS_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @sitesFrame = FXVerticalFrame.new(sitesArea, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0)
  
  list_sites
  
  updateFrame()
end

Instance Method Details

#editSiteDetails(site) ⇒ Object



200
201
202
203
204
205
206
207
# File 'lib/watobo/gui/define_scope_frame.rb', line 200

def editSiteDetails(site)
  dlg = EditScopeDetailsDialog.new(self, @scope[site])
  
  if dlg.execute != 0
    @scope[site].update dlg.details
    puts dlg.details.to_yaml
  end
end

#getScopeObject



209
210
211
212
213
214
215
216
# File 'lib/watobo/gui/define_scope_frame.rb', line 209

def getScope()
  scope = Hash.new
  @cb_sites.keys.each do |site|
    @scope.delete(site) if !@cb_sites[site].checked?
    # scope[site] = @scope[site] if @cb_sites[site].checked?
  end
  return @scope
end

#onDeselectAll(sender, sel, item) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'lib/watobo/gui/define_scope_frame.rb', line 180

def onDeselectAll(sender, sel, item)        
  @cb_sites.each_key do |site|        
    @cb_sites[site].setCheck(false)  
    @edit_btns[site].disable
  end
  @sel_all_btn.setFocus()
  @sel_all_btn.setDefault()
  
end

#onSelectAll(sender, sel, item) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/watobo/gui/define_scope_frame.rb', line 190

def onSelectAll(sender, sel, item)
  sites = []
  @cb_sites.each_key do |site|
    @cb_sites[site].setCheck(true)
    @edit_btns[site].enable
  end
  @desel_all_btn.setFocus()
  @desel_all_btn.setDefault()
end

#setScope(scope) ⇒ Object



227
228
229
230
231
232
233
# File 'lib/watobo/gui/define_scope_frame.rb', line 227

def setScope(scope)
  @scope = scope
  Watobo::Scope.each do |site, scope_def|         
    @scope[site].update @scope[site] if !@scope[site].nil?         
  end
  updateFrame()
end

#updateFrameObject



218
219
220
221
222
223
224
225
# File 'lib/watobo/gui/define_scope_frame.rb', line 218

def updateFrame()
  @scope.each do |site, scope|
    next if @cb_sites[site].nil? 
    @cb_sites[site].setCheck(scope[:enabled])
    @cb_sites[site].checked? ? @edit_btns[site].enable : @edit_btns[site].disable
  end
  
end