Class: DragonsKeep::KeepsMain

Inherits:
Wx::Frame
  • Object
show all
Defined in:
lib/dragons_keep/keeps_main.rb

Constant Summary collapse

ID_FILE_NEW =
1001
ID_FILE_CONNECT =
1002
ID_FILE_DISCONNECT =
1003
ID_ACCOUNT_NEW =
3001
ID_ACCOUNT_EDIT =
3002
ID_ACCOUNT_DELETE =
3003
ID_EDIT_COPY =
2001
ID_TOOL_NEW_ACCOUNT =
101
ID_TOOL_EDIT_ACCOUNT =
102
ID_TOOL_DELETE_ACCOUNT =
103

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ KeepsMain

Returns a new instance of KeepsMain.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dragons_keep/keeps_main.rb', line 22

def initialize(title)      
  #create an instance of frame
  super(nil, :title => title, :size => [ 400, 300 ])
  @account_controller = nil
  create_menu_bar
  # Create status bar with one cell
  create_status_bar(1)
  create_tb
  create_contents
  register_events
  
end

Instance Method Details

#on_connect_databaseObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dragons_keep/keeps_main.rb', line 59

def on_connect_database
  file_dialog = Wx::FileDialog.new(self, "Choose Keep File", :wildcard=>"Keep Files(*.keep)|*.keep")
  file_dialog.center_on_screen(Wx::BOTH)
  if file_dialog.show_modal == Wx::ID_OK
    password_dialog = Wx::PasswordEntryDialog.new(self, "Please enter the password for this database")
    if password_dialog.show_modal == Wx::ID_OK
      password = password_dialog.get_value
      file = file_dialog.get_path
      #puts file
      begin
        @account_controller = AccountController.new file, password
        @account_controller.establish_connection
        load_list
      rescue PasswordException
        dlg = Wx::MessageDialog.new(self, "The Password you entered is invalid", "Password", Wx::OK | Wx::ICON_ERROR)
        dlg.show_modal()
        @account_controller = nil
      end
    end
  end
end

#on_copy_passwordObject



120
121
122
123
124
125
126
# File 'lib/dragons_keep/keeps_main.rb', line 120

def on_copy_password
   = @list[@account_list.get_selection]
  @account_controller.decrypt!()
  Wx::Clipboard.open do | clip |
    clip.data = Wx::TextDataObject.new(.unencrypted_password)
  end
end

#on_delete_accountObject



112
113
114
115
116
117
118
119
# File 'lib/dragons_keep/keeps_main.rb', line 112

def 
   = @list[@account_list.get_selection]
    dlg = Wx::MessageDialog.new(self, "Are you sure you wish to delete account #{.name}", "Dragon's Keep", Wx::YES | Wx::NO | Wx::ICON_QUESTION)
  if dlg.show_modal() == Wx::ID_YES
    @account_controller.delete 
    load_list
  end
end

#on_disconnectObject



81
82
83
84
85
# File 'lib/dragons_keep/keeps_main.rb', line 81

def on_disconnect
  @account_controller = nil
  @list = nil
  @account_list.clear
end

#on_edit_accountObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/dragons_keep/keeps_main.rb', line 96

def 
  begin
     = @list[@account_list.get_selection]
    @account_controller.decrypt!()
     = AccountDialog.new(self, -1, "Edit Account")
    .center_on_screen(Wx::BOTH)
    . = 
    if .show_modal()== Wx::ID_OK
      @account_controller.save!(.)
      load_list
    end
  rescue PasswordException
     dlg = Wx::MessageDialog.new(self, "The Password you entered is invalid", "Password", Wx::OK | Wx::ICON_ERROR)
     dlg.show_modal()
  end
end

#on_new_accountObject



87
88
89
90
91
92
93
94
95
# File 'lib/dragons_keep/keeps_main.rb', line 87

def 
   = AccountDialog.new(self, -1, "New Account")
  .center_on_screen(Wx::BOTH)
  . = Account.new
  if .show_modal()== Wx::ID_OK
    @account_controller.save!(.)
    load_list
  end
end

#on_new_databaseObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dragons_keep/keeps_main.rb', line 40

def on_new_database
  file_dialog = Wx::FileDialog.new(self, "Choose File for new Database", :wildcard=>"Keep Files(*.keep)|*.keep", :style=>Wx::FD_SAVE)
  file_dialog.center_on_screen(Wx::BOTH)
  if file_dialog.show_modal == Wx::ID_OK
    password_dialog = Wx::PasswordEntryDialog.new(self, "Please enter a password for this database")
    if password_dialog.show_modal == Wx::ID_OK
      password = password_dialog.get_value
      file = file_dialog.get_path
      if (file=~/.keep$/) == nil
        file << ".keep"
      end
      #puts file
      @account_controller = AccountController.new file, password
      @account_controller.establish_connection          
      load_list
#          update_ui
    end
  end
end

#on_quitObject

End the application; it should finish automatically when the last window is closed.



37
38
39
# File 'lib/dragons_keep/keeps_main.rb', line 37

def on_quit
  close()
end