Class: Watobo::Plugin::Crawler::Gui::AuthFrame

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
plugins/crawler/gui/auth_frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, opts = {}) ⇒ AuthFrame

Returns a new instance of AuthFrame.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
# File 'plugins/crawler/gui/auth_frame.rb', line 170

def initialize(owner, opts={})
  super(owner, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK|FRAME_RAISED, :padding => 0)
  frame = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
  #left_frm = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_Y|FRAME_NONE)
  @event_dispatcher_listeners = Hash.new
  @crawler = opts[:crawler] if opts.has_key? :crawler
  @start_url = ""

  auth_gb= FXGroupBox.new(frame, "Authentication", LAYOUT_SIDE_RIGHT|FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0)
  auth_frm = FXVerticalFrame.new(auth_gb, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE)
  @auth_form = nil
  @auth_type_dt = FXDataTarget.new(0)

  @no_auth_rb = FXRadioButton.new(auth_frm, "None", @auth_type_dt, FXDataTarget::ID_OPTION)

  @basic_auth_rb = FXRadioButton.new(auth_frm, "Basic", @auth_type_dt, FXDataTarget::ID_OPTION + 1)

  @form_auth_rb = FXRadioButton.new(auth_frm, "Form", @auth_type_dt, FXDataTarget::ID_OPTION + 2)

  # group_box = FXGroupBox.new(self, "Collection",LAYOUT_SIDE_TOP|FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0)
  # frame = FXVerticalFrame.new(group_box, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_GROOVE)
  # @collectionList = FXList.new(frame, :opts => LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)

  @switcher = FXSwitcher.new(auth_frm,LAYOUT_FILL_X|LAYOUT_FILL_Y)
  frame = FXHorizontalFrame.new(@switcher, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE)
  FXLabel.new(frame, "No Authentication Selected", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  frame = FXHorizontalFrame.new(@switcher, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE)
  FXLabel.new(frame, "Username:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @basic_auth_user_txt = FXTextField.new(frame, 10, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT)
  FXLabel.new(frame, "Password:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @basic_auth_passwd_txt = FXTextField.new(frame, 10, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT|TEXTFIELD_PASSWD)
  FXLabel.new(frame, "Retype:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @basic_auth_retype_txt = FXTextField.new(frame, 10, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_RIGHT|TEXTFIELD_PASSWD)

  form_auth_frame = FXVerticalFrame.new(@switcher, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE)
  frame = FXHorizontalFrame.new(form_auth_frame, :opts => LAYOUT_FILL_X|FRAME_NONE)
  FXLabel.new(frame, "URL of LoginForm, leave empty to use Start URL:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @form_auth_url_txt = FXTextField.new(frame, 10, nil, 0, :opts => TEXTFIELD_NORMAL|LAYOUT_FILL_X)
  @fetch_button = FXButton.new(frame, "load page", :opts => BUTTON_DEFAULT|BUTTON_NORMAL )

  form_frame = FXHorizontalFrame.new(form_auth_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE)
  frame = FXHorizontalFrame.new(form_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0)
  @page_tree = Watobo::Gui::PageTree.new(frame)
  frame = FXHorizontalFrame.new(form_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK)
  @form_fields_table = FormFieldsTable.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)

  @auth_type_dt.connect(SEL_COMMAND) {
    @basic_auth_rb.handle(self, FXSEL(SEL_UPDATE, 0), nil)
    @form_auth_rb.handle(self, FXSEL(SEL_UPDATE, 0), nil)
    @no_auth_rb.handle(self, FXSEL(SEL_UPDATE, 0), nil)
    @switcher.current = @auth_type_dt.value
  }
  
  @basic_auth_passwd_txt.connect(SEL_CHANGED){ password_check }
   @basic_auth_retype_txt.connect(SEL_CHANGED){ password_check }

  @fetch_button.connect(SEL_COMMAND){
    begin
      @form_fields_table.clear_fields
      @page_tree.clearItems

      page = nil
      url = nil
     
     if @form_auth_url_txt.text.empty?
      unless Watobo::Plugin::Crawler.start_url.nil?
        uri = Watobo::Plugin::Crawler.start_url
      end
      else
         url = @form_auth_url_txt.text unless @form_auth_url_txt.text.empty?
        uri = URI.parse(url) 
      end

      notify(:log, "GET PAGE << #{uri.to_s}")
      @agent, page = @crawler.get_page(uri)
      notify(:log, "PAGE LOADED")
      @page_tree.page = page
    rescue => bang
      notify(:log, "could not get page #{uri.to_s}")
      puts "Could not get page for #{uri.to_s}"
      puts bang
      puts bang.backtrace if $DEBUG
    end
    true
  }
  @switcher.current = @auth_type_dt.value

  @page_tree.subscribe(:form_selected){|form|
    @auth_form = form
    @form_fields_table.clear_fields
    form.fields.each do |field|
      @form_fields_table.add_field field
    end
    form.buttons.each do |field|
      @form_fields_table.add_field field
    end
  }

end

Instance Attribute Details

#crawlerObject

Returns the value of attribute crawler.



108
109
110
# File 'plugins/crawler/gui/auth_frame.rb', line 108

def crawler
  @crawler
end

Instance Method Details

#clearEvents(event) ⇒ Object



113
114
115
# File 'plugins/crawler/gui/auth_frame.rb', line 113

def clearEvents(event)
  @event_dispatcher_listener[event].clear
end

#set(settings) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'plugins/crawler/gui/auth_frame.rb', line 117

def set(settings)
  return false unless settings.has_key? :auth_type
  if settings[:auth_type] == :basic
    @auth_type_dt.value = 1
    @basic_auth_user_txt.text = settings.has_key?(:username) ? settings[:username] : ""
    pw = settings.has_key?(:password) ? settings[:password] : ""
    @basic_auth_passwd_txt.text = pw
    @basic_auth_retype_txt.text = pw
    
  end
   @switcher.current = @auth_type_dt.value
   update_form
   return true
end

#subscribe(event, &callback) ⇒ Object



109
110
111
# File 'plugins/crawler/gui/auth_frame.rb', line 109

def subscribe(event, &callback)
  (@event_dispatcher_listeners[event] ||= []) << callback
end

#to_hObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'plugins/crawler/gui/auth_frame.rb', line 132

def to_h
  a = case @auth_type_dt.value
  when 0
    {
      :auth_type => :none
    }
  when 1
    {
      :auth_type => :basic,
      :username => @basic_auth_user_txt.text,
      :password => @basic_auth_passwd_txt.text,
      :retype => @basic_auth_retype_txt.text
      #  :uri => URI.parse
    }
  when 2
    @form_fields_table.update_fields

    {
      :auth_type => :form,
      :form => @auth_form,
      :cookie_jar => @agent.respond_to?(:cookie_jar) ? @agent.cookie_jar : nil
    }
  end
  a

end

#update_formObject

def set(settings)

@form_auth_url_txt.text = settings[:form_auth_url].to_s if settings.has_key? :form_auth_url
update_form

end



164
165
166
167
168
# File 'plugins/crawler/gui/auth_frame.rb', line 164

def update_form
  [ @form_auth_url_txt, @no_auth_rb, @basic_auth_rb, @form_auth_rb ].each do |e|
    e.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  end
end