Class: UI

Inherits:
FXMainWindow
  • Object
show all
Defined in:
lib/bitferry/fx.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ UI

Returns a new instance of UI.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bitferry/fx.rb', line 27

def initialize(app)
  super(@app = app, 'BitferryFX', width: 400, height: 300)
  top_frame = FXVerticalFrame.new(self, opts: LAYOUT_FILL)
    tabs = FXTabBook.new(top_frame, opts: LAYOUT_FILL)
      output_tab = FXTabItem.new(tabs, 'Output')
        @output = FXText.new(tabs)
      tasks_tab = FXTabItem.new(tabs, 'Tasks')
        @tasks = FXTable.new(tabs)
        @tasks.tableStyle |= TABLE_COL_SIZABLE | TABLE_NO_COLSELECT | TABLE_READONLY
        @tasks.rowHeaderMode = LAYOUT_FIX_WIDTH
        @tasks.rowHeaderWidth = 0
      volumes_tab = FXTabItem.new(tabs, 'Volumes')
        @volumes = FXTable.new(tabs)
        @volumes.tableStyle |= TABLE_COL_SIZABLE | TABLE_NO_COLSELECT | TABLE_READONLY
        @volumes.rowHeaderMode = LAYOUT_FIX_WIDTH
        @volumes.rowHeaderWidth = 0
    @progress = FXProgressBar.new(top_frame, height: 16, opts: LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT)
    controls = FXPacker.new(top_frame, opts: LAYOUT_FILL_X)
      @simulate = FXCheckButton.new(controls, "&Simulation mode (dry run)\tPrevent operations from making any on-disk changes")
        @simulate.checkState = Bitferry.simulate?
      @verbose = FXCheckButton.new(controls, "&Verbose mode\tOutput internal logging information")
      @verbose.checkState = false
    buttons = FXPacker.new(top_frame, opts: LAYOUT_FILL_X | PACK_UNIFORM_WIDTH | FRAME_SUNKEN)
      @process = FXButton.new(buttons, "&Process\tProcess all intact tasks", opts: BUTTON_NORMAL | BUTTON_INITIAL | BUTTON_DEFAULT | LAYOUT_SIDE_LEFT)
        @process.connect(SEL_COMMAND) { process }
        @process.setFocus
      @quit = FXButton.new(buttons, "&Quit\tStop any pending operations and exit", opts: BUTTON_NORMAL | LAYOUT_SIDE_RIGHT)
        @quit.connect(SEL_COMMAND) { exit }
      @reload = FXButton.new(buttons, "&Reload\tReread volumes and tasks to capture volume changes", opts: BUTTON_NORMAL | LAYOUT_SIDE_RIGHT)
        @reload.connect(SEL_COMMAND) { reset }
  @sensible = [@process, @reload] # Controls which must be disabled during processing
  reset
end

Instance Method Details

#createObject



117
118
119
120
# File 'lib/bitferry/fx.rb', line 117

def create
  super
  show(PLACEMENT_SCREEN)
end

#processObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bitferry/fx.rb', line 61

def process
  Bitferry.simulate = @simulate.checked?
  Bitferry.verbosity = @verbose.checked? ? :verbose : :default
  @progress.setBarColor(:blue)
  @progress.progress = 0
  @output.text = nil
  Thread.new {
    @app.runOnUiThread { @sensible.each(&:disable) }
    begin
      Bitferry.process { |total, processed, failed|
        @app.runOnUiThread {
          @progress.setBarColor(:red) if failed > 0
          @progress.progress = processed
          @progress.total = total
        }
      }
    ensure
      @app.runOnUiThread { @sensible.each(&:enable) }
    end
  }
end

#resetObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bitferry/fx.rb', line 83

def reset
  Bitferry.restore
  @progress.progress = 0
  $stdout = Output.new(@app, @output)
  Bitferry::Logging.log = log = Logger.new($stdout)
  log.progname = :bitferryfx
  log.level = Logger::WARN
  #
  @volumes.setTableSize(Bitferry::Volume.intact.size, 2)
  @volumes.setColumnText(0, 'Volume')
  @volumes.setColumnText(1, 'Root')
  i = 0
  Bitferry::Volume.intact.each do |v|
    @volumes.setItemText(i, 0, v.tag)
    @volumes.setItemText(i, 1, v.root.to_s)
    i += 1
  end
  #
  @tasks.setTableSize(Bitferry::Task.intact.size, 4)
  @tasks.setColumnText(0, 'Task')
  @tasks.setColumnText(1, 'Operation')
  @tasks.setColumnText(2, 'Source')
  @tasks.setColumnText(3, 'Destination')
  i = 0
  Bitferry::Task.intact.each do |t|
    @tasks.setItemText(i, 0, t.tag)
    @tasks.setItemText(i, 1, t.show_operation)
    @tasks.setItemText(i, 2, t.source.show_status)
    @tasks.setItemText(i, 3, t.destination.show_status)
    i += 1
  end
  #
end