Class: Watobo::Gui::ProxyDialog

Inherits:
FXDialogBox
  • Object
show all
Includes:
Responder
Defined in:
lib/watobo/gui/proxy_dialog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ ProxyDialog

Returns a new instance of ProxyDialog.


454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/watobo/gui/proxy_dialog.rb', line 454

def initialize(owner)
  super(owner, "Use Proxy", :opts => DECOR_ALL, :width => 250, :height => 400)
  @new_proxy = FXDataTarget.new('')
  @save_passwords = false
  
  @proxy_settings = Hash.new
  @proxy_settings.update(Watobo::Conf::ForwardingProxy.to_h)

#  @password_policy = password_policy

  @proxy = nil
  pname = @proxy_settings[:default_proxy]
  @proxy_settings ||= {}
  if @proxy_settings.has_key? pname
  @proxy = @proxy_settings[pname]
  end

  @proxy_list = {}
  @proxy_list.update YAML.load(YAML.dump(@proxy_settings))
  @proxy_list.delete(:default_proxy)

  FXMAPFUNC(SEL_COMMAND, ID_ACCEPT, :onAccept)
  FXMAPFUNC(SEL_COMMAND, ID_CANCEL, :onCancel)

  current_proxy_frame = FXHorizontalFrame.new(self,FRAME_NONE|LAYOUT_FILL_X|FRAME_GROOVE)
  FXLabel.new(current_proxy_frame, "Current Proxy:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @cp_label = FXLabel.new(current_proxy_frame, "- none -", nil, LAYOUT_TOP|JUSTIFY_RIGHT)

  main_frame = FXVerticalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  enable_proxy_frame = FXHorizontalFrame.new(main_frame,FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @proxyEnableCheckButton = FXCheckButton.new(enable_proxy_frame, "enable forwarding proxy", nil, 0, ICON_BEFORE_TEXT|LAYOUT_SIDE_LEFT)

  @proxyEnableCheckButton.connect(SEL_COMMAND) do |sender, sel, item|
    switchEnableProxy()
  end

  @proxySelectionFrame = FXGroupBox.new(main_frame, "Select Forwarding Proxy", LAYOUT_SIDE_TOP|FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0)

  proxySubSelection = FXVerticalFrame.new(@proxySelectionFrame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE)

  @proxyTable = FXTable.new(proxySubSelection,
  :opts => TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y|TABLE_READONLY,
  :padding => 2)
  @proxyTable.setTableSize(0, 2)

  @proxyTable.connect(SEL_COMMAND, method(:onProxySelect))
  @proxyTable.connect(SEL_SELECTED, method(:onProxySelect))

  @proxyTable.rowHeaderWidth = 0
  @proxyTable.rowHeaderMode = LAYOUT_FIX_WIDTH

  @proxyTable.visibleRows = 5
  @proxyTable.setColumnText(0, "Name" )
  @proxyTable.setColumnText(1, "Proxy" )

  buttons_frame = FXHorizontalFrame.new( proxySubSelection, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @newProxyButton = FXButton.new(buttons_frame, "Add" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
  @newProxyButton.connect(SEL_COMMAND){ addProxy() }

  @editProxyButton = FXButton.new(buttons_frame, "Edit" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
  @editProxyButton.connect(SEL_COMMAND) { editProxy() }
  @editProxyButton.disable

  @delProxyButton = FXButton.new(buttons_frame, "Delete" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
  @delProxyButton.connect(SEL_COMMAND, method(:delProxy))
  @delProxyButton.disable

  selection_frame = FXHorizontalFrame.new(main_frame,FRAME_NONE|LAYOUT_FILL_X)
  @proxy_prelabel = FXLabel.new(selection_frame, "Selected Proxy:", nil, LAYOUT_TOP|JUSTIFY_RIGHT)
  @proxy_label = FXLabel.new(selection_frame, "- none -", nil, LAYOUT_TOP|JUSTIFY_RIGHT)

  buttons = FXHorizontalFrame.new(main_frame, :opts => LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,
  :padLeft => 40, :padRight => 40, :padTop => 20, :padBottom => 20)

  # Accept
  @acceptBtn = FXButton.new(buttons, "&Accept", nil, self, ID_ACCEPT,
  FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT|LAYOUT_CENTER_Y)
  @acceptBtn.disable
  # Cancel
  FXButton.new(buttons, "&Cancel", nil, self, ID_CANCEL,
  FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT|LAYOUT_CENTER_Y)

  @proxyEnableCheckButton.setCheck(false, false)
  @proxyEnableCheckButton.setCheck(true, false) unless @proxy.nil?
  refreshProxyList()
  switchEnableProxy()

  unless @proxy.nil?
    @cp_label.text = @proxy[:name]
    selectProxy(@proxy)
  end

end

Instance Attribute Details

#proxyObject

TODO: Implement Connection Check!!


270
271
272
# File 'lib/watobo/gui/proxy_dialog.rb', line 270

def proxy
  @proxy
end

Instance Method Details

#addProxy(proxy = nil) ⇒ Object


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/watobo/gui/proxy_dialog.rb', line 331

def addProxy(proxy=nil)
  pdlg = AddProxyDialog.new(self, proxy)

  if pdlg.execute != 0
    @acceptBtn.enable
    @acceptBtn.setFocus()
    @acceptBtn.setDefault()

    last = @proxyTable.getNumRows
    @proxy = pdlg.getProxySettings
    @save_passwords = pdlg.savePasswords?
    @proxy_list[@proxy[:name]] = @proxy

    addProxyItem( @proxy )
    
    lastRowIndex = @proxyTable.numRows
    last = -1
    lastRowIndex.times do |i|
      if @proxyTable.getItemText(i, 0) == @proxy[:name] then
      last = i
      break
      end
    end
    return -1 if last == -1

    @proxyTable.selectRow(last)
    @proxyTable.makePositionVisible(last,0)
    @proxy_label.text = @proxy[:name]
  end
end

#addProxyItem(proxy) ⇒ Object


433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/watobo/gui/proxy_dialog.rb', line 433

def addProxyItem(proxy)
 # puts proxy.to_yaml
  lastRowIndex = @proxyTable.numRows
  siteIndex = -1
  lastRowIndex.times do |i|
    if @proxyTable.getItemText(i, 0) == proxy[:name] then
    siteIndex = i
    lastRowIndex = i
    break
    end
  end
  @proxyTable.appendRows(1) if siteIndex < 0

  @proxyTable.rowHeader.setItemJustify(lastRowIndex,FXTableItem::LEFT)
  @proxyTable.setItemText(lastRowIndex, 0, proxy[:name])
  @proxyTable.getItem(lastRowIndex,0).justify = FXTableItem::LEFT
  @proxyTable.setItemText(lastRowIndex, 1, proxy[:host] + ":" + proxy[:port])
  @proxyTable.setItemData(lastRowIndex, 0, proxy)
  @proxyTable.getItem(lastRowIndex,1).justify = FXTableItem::LEFT
end

#delProxy(sender, sel, event) ⇒ Object


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/watobo/gui/proxy_dialog.rb', line 362

def delProxy(sender, sel, event)

  row = @proxyTable.getCurrentRow
  #  puts row
  if row >= 0 and @proxyTable.rowSelected?(row) then
    p = @proxyTable.getItem(row,1).to_s
    #puts @proxy.class.to_s
    #   puts "delete: #{proxy}"
    @proxy = ''
    @proxyTable.removeRows(row,1)
    @proxyTable.killSelection(true)
    @delProxyButton.disable
    @acceptBtn.disable
    @proxy_label.text = ''
  end
end

#editProxyObject


379
380
381
382
383
384
385
386
387
# File 'lib/watobo/gui/proxy_dialog.rb', line 379

def editProxy()
  row = @proxyTable.getCurrentRow
  puts row
  if row >= 0 and @proxyTable.rowSelected?(row) then
    #p = @proxyTable.getItem(row,1).to_s
    proxy = @proxyTable.getItemData(row,0)
    addProxy(proxy)
  end
end

#getProxyPrefsObject


304
305
306
307
# File 'lib/watobo/gui/proxy_dialog.rb', line 304

def getProxyPrefs()
  @proxy_list[:default_proxy] = @proxy.nil? ? '' : @proxy[:name]
  @proxy_list
end

#onAccept(sender, sel, event) ⇒ Object


309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/watobo/gui/proxy_dialog.rb', line 309

def onAccept(sender, sel, event)
  # @settings[:proxies] = proxies
  @proxy_list = Hash.new
  lastRowIndex = @proxyTable.numRows
  lastRowIndex.times do |i|
    proxy = @proxyTable.getItemData(i,0)
    # puts proxy.to_yaml
    @proxy_list[proxy[:name]] = proxy
  end
#  @password_policy[:save_passwords] = @save_passwords
  getApp().stopModal(self, 1)
  self.hide()
  return 1

end

#onCancel(sender, sel, event) ⇒ Object


325
326
327
328
329
# File 'lib/watobo/gui/proxy_dialog.rb', line 325

def onCancel(sender, sel, event)
  getApp().stopModal(self, 0)
  self.hide()
  return 1
end

#onProxySelect(sender, sel, index) ⇒ Object


389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/watobo/gui/proxy_dialog.rb', line 389

def onProxySelect(sender, sel, index)

  row = sender.getCurrentRow
  if row >= 0 then
    @proxyTable.selectRow(row)
    @proxy = @proxyTable.getItemData(row,0)
    @proxy_label.text = @proxy[:name]
  @delProxyButton.enable
  @editProxyButton.enable
  @acceptBtn.enable
  @acceptBtn.setFocus()
  @acceptBtn.setDefault()
  end
end

#refreshProxyListObject


294
295
296
297
298
299
300
301
302
# File 'lib/watobo/gui/proxy_dialog.rb', line 294

def refreshProxyList
  @proxyTable.clearItems(false)
  @proxyTable.setTableSize(0, 2)
  return if @proxy_list.nil?
  @proxy_list.each_key do |proxy|
    puts "* addProxyItem #{proxy}"
    addProxyItem(@proxy_list[proxy])
  end
end

#selectProxy(proxy = {}) ⇒ Object


404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/watobo/gui/proxy_dialog.rb', line 404

def selectProxy(proxy={})
  @editProxyButton.disable
  @delProxyButton.disable
  @proxyTable.killSelection(true)
  @proxy_label.text = "- none -"
  @proxy = nil
  return false if proxy.nil?
  return false unless proxy[:name]
  proxy_name = proxy[:name]
  i = 0
  @proxyTable.each do |items|
    if items[0].to_s == proxy_name
      puts "* match #{proxy_name}"
    @proxyTable.selectRow(i)
    @proxyTable.setCurrentItem(i,0)
    @proxyTable.makePositionVisible(i,0)
    @proxy = @proxyTable.getItemData(i,0)
    #  puts @proxy
    @proxy_label.text = proxy_name
    @delProxyButton.enable
    end
    i += 1
  end
  unless @proxy.nil?
  @editProxyButton.enable
  @delProxyButton.enable
  end
end

#switchEnableProxyObject


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/watobo/gui/proxy_dialog.rb', line 273

def switchEnableProxy()
  if not @proxyEnableCheckButton.checked? then
    @proxyTable.hide()
    @newProxyButton.disable
    @delProxyButton.disable
    @editProxyButton.disable
    @acceptBtn.enable
    @proxy = nil
  @proxyTable.killSelection()
  else
    @proxyTable.show()
    @newProxyButton.enable
    selectProxy(@proxy)
    @acceptBtn.disable
    refreshProxyList()
  end
  @proxySelectionFrame.enabled = @proxyEnableCheckButton.checked?
  @proxy_prelabel.enabled = @proxyEnableCheckButton.checked?
  @proxy_label.enabled = @proxyEnableCheckButton.checked?
end