PageRenderTime 45ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/database_dialog.rb

https://bitbucket.org/magesh/mycash
Ruby | 99 lines | 72 code | 6 blank | 21 comment | 5 complexity | 58c06b0421a0615702f7a23c5a41c774 MD5 | raw file
  1. # This program is free software: you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation, version 3 of the License.
  4. #
  5. # This program is distributed in the hope that it will be useful,
  6. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. # GNU General Public License for more details.
  9. #
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. #
  13. # Copyright: (C) 2004-2010 Rafal Kotusiewicz aka 'jjhop'. All rights reserved.
  14. #
  15. # http://bitbucket.org/jjhop/mycash/overview/
  16. # http://bitbucket.org/jjhop/mycash/wiki/Home
  17. #
  18. require "fox16"
  19. include Fox
  20. class OpenDatabaseDialog < FXDialogBox
  21. def initialize(parent)
  22. # Najpierw inicjalizacja potrzebnych zmiennych...
  23. @current_selection = nil
  24. # Teraz budujemy okno, kontrolki itd
  25. super(parent, "Wybor bazy", DECOR_BORDER|DECOR_TITLE|DECOR_CLOSE|DECOR_RESIZE, 0, 0, 240, 300)
  26. FXGIFIcon.new(getApp(), File.open(File.join(File.dirname(__FILE__), './ico/16/book.gif'),"rb").read) do |ico|
  27. self.icon = ico
  28. end
  29. FXVerticalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y,0, 0, 0, 0, 0, 0, 0, 0) do |contents|
  30. FXGroupBox.new(contents, nil, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK|FRAME_SUNKEN, 0, 0, 0, 0, 0, 0, 0, 0) do |group_all|
  31. FXList.new(group_all, nil, 0, LIST_SINGLESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT) do |list|
  32. # TODO: katalog powinien pochodzic z konfiguracji - uwaga na polskie znaki!
  33. db_directory_name = "c:\\dev\\ruby\\mycash\\.db\\"
  34. Dir.open(db_directory_name) do |dir|
  35. if dir == nil
  36. Dir.mkdir(db_directory_name)
  37. else
  38. dir.each do |file|
  39. if File.extname(file) == ".db"
  40. list.appendItem(file)
  41. end
  42. end
  43. end
  44. end
  45. list.connect(SEL_SELECTED) do |sender, sel, index|
  46. @current_selection = list.getItem(index).text
  47. self.change_state(true)
  48. end
  49. list.connect(SEL_DESELECTED) do |sender, sel, index|
  50. @current_selection = nil
  51. self.change_state(false)
  52. end
  53. end
  54. end
  55. @auth_box = FXGroupBox.new(contents, "Dane logowania...", LAYOUT_FILL_X|FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0) do |auth_box|
  56. FXMatrix.new(auth_box, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL) do |auth_matrix|
  57. @auth_user_lbl = FXLabel.new(auth_matrix, "Uzytkownik:", nil, 1, LAYOUT_FILL_X|FRAME_LINE)
  58. @auth_user_tbx = FXTextField.new(auth_matrix, 20, nil, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X)
  59. @auth_pass_lbl = FXLabel.new(auth_matrix, "Haslo:", nil, 1, LAYOUT_FILL_X|FRAME_LINE)
  60. @auth_pass_tbx = FXTextField.new(auth_matrix, 20, nil, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|TEXTFIELD_PASSWD) do |passwTbox|
  61. passwTbox.tipText = 'Tutaj wprowadz haslo'
  62. end
  63. end
  64. # chowamy częœć, skoro sqlite3 nie obsługuje uwierzytelniania
  65. auth_box.hide
  66. end
  67. FXMatrix.new(contents, 2, MATRIX_BY_COLUMNS|LAYOUT_RIGHT) do |btn_matrix|
  68. @open_btn = FXButton.new(btn_matrix, "&Otworz", nil, self, ID_ACCEPT, FRAME_RAISED|FRAME_THICK|BUTTON_DEFAULT) do |btn|
  69. btn.padLeft = 6
  70. btn.padRight = 6
  71. btn.padTop = 3
  72. btn.padBottom = 3
  73. btn.disable
  74. end
  75. FXButton.new(btn_matrix, "&Anuluj", nil, self, ID_CANCEL, FRAME_RAISED|FRAME_THICK|BUTTON_DEFAULT) do |btn|
  76. btn.padLeft = 6
  77. btn.padRight = 6
  78. btn.padTop = 3
  79. btn.padBottom = 3
  80. end
  81. end
  82. end
  83. self.change_state(false)
  84. end
  85. def change_state(new_state)
  86. [@open_btn, @auth_box, @auth_user_lbl, @auth_user_tbx, @auth_pass_lbl, @auth_pass_tbx].each do |c|
  87. new_state == true ? c.enable : c.disable
  88. end
  89. end
  90. def current_selection
  91. @current_selection
  92. end
  93. end