155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
|
# File 'plugins/crawler/gui/auth_frame.rb', line 155
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)
@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)
@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
|