Class: VaultGUI::GUI

Inherits:
Frame
  • Object
show all
Defined in:
lib/gui.rb

Instance Method Summary collapse

Constructor Details

#initializeGUI

Returns a new instance of GUI.



23
24
25
26
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
60
61
62
63
64
65
66
67
68
69
# File 'lib/gui.rb', line 23

def initialize
  super(nil, 0, "Password Vault GUI",
    :style => DEFAULT_FRAME_STYLE ^ RESIZE_BORDER ^ MAXIMIZE_BOX)

  ask_password()

  vbox = BoxSizer.new(VERTICAL)
  pl = PasswordList.new(self)
  evt_list_item_activated(pl) { |event|
    item_activated(pl.get_item(event.get_index, 0).get_text())
  }
  panel = Panel.new(self)

  hbox = BoxSizer.new(HORIZONTAL)
  add_button = Button.new(panel, :label=>"ADD", :size => [80, 20])
  evt_button(add_button) {
    check_and_reset_timer()
    add_pushed(pl)
  }
  remove_button = Button.new(panel, :label=>"REMOVE", :size => [80, 20])
  evt_button(remove_button) {
    check_and_reset_timer()
    remove_pushed(pl)
  }
  edit_button = Button.new(panel, :label=>"EDIT", :size => [80, 20])
  evt_button(edit_button) {
    check_and_reset_timer()
    edit_pushed(pl)
  }
  hbox.add(add_button)
  hbox.add(remove_button)
  hbox.add(edit_button)
  panel.set_sizer(hbox)

  vbox.add(pl)
  vbox.add(panel)
  self.set_sizer(vbox)
  vbox.set_size_hints( self )
  self.centre

  evt_close() { |event|
    VaultGUI.vault.destroy
    self.destroy
  }

  @timer = Time.now.to_i
end

Instance Method Details

#add_pushed(pl) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/gui.rb', line 107

def add_pushed(pl)
  add_popup = AddPopup.new(self)
  add_popup.show
  evt_button(add_popup) {
    new_name = add_popup.get_name_value
     = add_popup.
    new_password = add_popup.get_password_value
    begin
      VaultGUI.vault.add(new_name, , new_password)
      pl.insert_item(ListItem.new)
      add_popup.destroy
    rescue => e
      display_error_if_needed(e)
      add_popup.destroy
    end
  }
end

#ask_passwordObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/gui.rb', line 71

def ask_password()
  password_popup = PasswordPopup.new(self)
  if password_popup.show_modal == ID_OK
    pass_candidate = password_popup.get_value()
    begin
      VaultGUI.vault.authenticate(pass_candidate)
    rescue => e
      Kernel.raise e unless e.message == Vault::AUTHENTICATION_ERROR
      ErrorPopup.new("Error: wrong password!", "Error: wrong password!", true)
    end
  else
    Kernel.exit
  end
end

#check_and_reset_timerObject



86
87
88
89
90
91
92
93
# File 'lib/gui.rb', line 86

def check_and_reset_timer()
  now = Time.now.to_i
  if now - @timer > TIMEOUT
    VaultGUI.vault.deauthenticate()
    ask_password()
  end
  @timer = now
end

#display_error_if_needed(e) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/gui.rb', line 155

def display_error_if_needed(e)
  if e.class == Vault::CredentialError
    ErrorPopup.new(e.message, "Credential error", false)
  else
    Kernel.raise e
  end
end

#edit_pushed(pl) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/gui.rb', line 135

def edit_pushed(pl)
  selection = pl.get_selections
  if selection.length > 0
    index_edited = selection[0]
    edit_popup = EditPopup.new(self)
    edit_popup.show
    evt_button(edit_popup) {
      name = pl.get_item(index_edited, 0).get_text
       = edit_popup.
      new_password = edit_popup.get_password_value
      begin
        VaultGUI.vault.edit(name, , new_password)
        edit_popup.destroy
      rescue => e
        display_error_if_needed(e)
      end
    }
  end
end

#item_activated(name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gui.rb', line 95

def item_activated(name)
  info_popup = ViewPopup.new(self)
  loginPassword = VaultGUI.vault.credential(name)
  info_popup.set_name_value(name)
  info_popup.(loginPassword[0])
  info_popup.set_password_value(loginPassword[1])
  info_popup.show
  evt_button(info_popup) {
    info_popup.destroy
  }
end

#remove_pushed(pl) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/gui.rb', line 125

def remove_pushed(pl)
  selection = pl.get_selections
  if selection.length > 0
    index_deleted = selection[0]
    deleted = pl.get_item(index_deleted, 0).get_text
    pl.delete_item(index_deleted)
    VaultGUI.vault.remove(deleted)
  end
end