/database_dialog.rb
Ruby | 102 lines | 73 code | 6 blank | 23 comment | 5 complexity | 00e0c5668e3828267aab03940530b42c MD5 | raw file
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 3 of the License.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # Copyright: (C) 2004-2010 Rafal Kotusiewicz aka 'jjhop'. All rights reserved.
- #
- # http://bitbucket.org/jjhop/mycash/overview/
- # http://bitbucket.org/jjhop/mycash/wiki/Home
- #
-
- require "fox16"
- include Fox
-
- # Okno dialogowe pozwalajace otworzyc jedna z istniejacych
- # baz danych finansowych (np. dom, firma itd)
- class OpenDatabaseDialog < FXDialogBox
- def initialize(parent)
-
- # Najpierw inicjalizacja potrzebnych zmiennych...
- @current_selection = nil
-
- # Teraz budujemy okno, kontrolki itd
- super(parent, "Wybor bazy", DECOR_BORDER|DECOR_TITLE|DECOR_CLOSE|DECOR_RESIZE, 0, 0, 240, 300)
- FXGIFIcon.new(getApp(), File.open(File.join(File.dirname(__FILE__), './ico/16/book.gif'),"rb").read) do |ico|
- self.icon = ico
- end
- FXVerticalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y,0, 0, 0, 0, 0, 0, 0, 0) do |contents|
- 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|
- FXList.new(group_all, nil, 0, LIST_SINGLESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT) do |list|
- # TODO: katalog powinien pochodzic z konfiguracji - uwaga na polskie znaki!
- db_directory_name = "c:\\dev\\ruby\\mycash\\.db\\"
- db_directory_name = ".db/"
- Dir.open(db_directory_name) do |dir|
- if dir == nil
- Dir.mkdir(db_directory_name)
- else
- dir.each do |file|
- if File.extname(file) == ".db"
- list.appendItem(file)
- end
- end
- end
- end
- list.connect(SEL_SELECTED) do |sender, sel, index|
- @current_selection = list.getItem(index).text
- self.change_state(true)
- end
- list.connect(SEL_DESELECTED) do |sender, sel, index|
- @current_selection = nil
- self.change_state(false)
- end
- end
- end
- @auth_box = FXGroupBox.new(contents, "Dane logowania...", LAYOUT_FILL_X|FRAME_THICK, 0, 0, 0, 0, 0, 0, 0, 0) do |auth_box|
- FXMatrix.new(auth_box, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL) do |auth_matrix|
- @auth_user_lbl = FXLabel.new(auth_matrix, "Uzytkownik:", nil, 1, LAYOUT_FILL_X|FRAME_LINE)
- @auth_user_tbx = FXTextField.new(auth_matrix, 20, nil, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X)
- @auth_pass_lbl = FXLabel.new(auth_matrix, "Haslo:", nil, 1, LAYOUT_FILL_X|FRAME_LINE)
- @auth_pass_tbx = FXTextField.new(auth_matrix, 20, nil, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|TEXTFIELD_PASSWD) do |passwTbox|
- passwTbox.tipText = 'Tutaj wprowadz haslo'
- end
- end
- # chowamy t? cz?œ?, skoro sqlite3 nie obs?uguje uwierzytelniania
- auth_box.hide
- end
- FXMatrix.new(contents, 2, MATRIX_BY_COLUMNS|LAYOUT_RIGHT) do |btn_matrix|
- @open_btn = FXButton.new(btn_matrix, "&Otworz", nil, self, ID_ACCEPT, FRAME_RAISED|FRAME_THICK|BUTTON_DEFAULT) do |btn|
- btn.padLeft = 6
- btn.padRight = 6
- btn.padTop = 3
- btn.padBottom = 3
- btn.disable
- end
- FXButton.new(btn_matrix, "&Anuluj", nil, self, ID_CANCEL, FRAME_RAISED|FRAME_THICK|BUTTON_DEFAULT) do |btn|
- btn.padLeft = 6
- btn.padRight = 6
- btn.padTop = 3
- btn.padBottom = 3
- end
- end
- end
- self.change_state(false)
- end
-
- def change_state(new_state)
- [@open_btn, @auth_box, @auth_user_lbl, @auth_user_tbx, @auth_pass_lbl, @auth_pass_tbx].each do |c|
- new_state == true ? c.enable : c.disable
- end
- end
-
- def current_selection
- @current_selection
- end
- end