require_relative 'base' require_relative 'toolbox' require_relative '../util/cache' require_relative '../sessions' require 'manabu/client' module ManabuDesktop module Screens class Login < ManabuDesktop::Screens::Base attr_accessor :cache_info, :client CACHE_FILE_NAME = "login_cache.manabu" def initialize() super('login') _load_cache() @window.resizable = false @builder.get_object('server.label').set_label(I18n.t('login.server')) @builder.get_object('secure.label').set_label(I18n.t('login.secure')) @server_comboboxtext = @builder.get_object('server.comboboxtext') @server_secure_switch = @builder.get_object('secure.switch') @cache_info[:servers].each{ |server| @server_comboboxtext.append_text(server[:addr])} if (@cache_info[:servers].length > 0) @server_comboboxtext.set_active(0) @server_secure_switch.active = @cache_info[:servers][0][:secure] end # TODO: set server details when selection is changed # TODO: allow deletion of a server entry # TODO: save new servers @builder.get_object('user.label').set_label(I18n.t('login.user')) @user_entry = @builder.get_object('user.entry') @builder.get_object('password.label').set_label(I18n.t('login.password')) @password_entry = @builder.get_object('password.entry') engage_button = @builder.get_object('engage.button') engage_button.set_label(I18n.t('login.engage')) engage_button.signal_connect('clicked') { _engage(@server_comboboxtext.active_text, @server_secure_switch.active?, @user_entry.text, @password_entry.text) } _show() end def _load_cache() @cache_info = ManabuDesktop::Util::Cache.load(CACHE_FILE_NAME) if (@cache_info === {} || !@cache_info.includes?(:servers) || !@cache_info[:servers].instance_of?(Array)) @cache_info = { servers: [{addr: 'localhost:9000', secure: false}] } end end def _save_cache() end def _engage(server, secure, user, password) addr = /^[^:|^\/]*[^:|^\/]/.match(server) # server part port = /[^:]\d[^\D]*/.match(server).to_s.to_i # port part port = 80 if (port == 0) route = /\/.*$/.match(server) #route part @client = Manabu::Client.new(user, password, "#{addr}#{route}", port, force_secure_connection: secure) if @client.status == :connected _open_toolbox(@client) end end def _open_toolbox(client) @window.destroy ManabuDesktop::Screens::ToolBox.new(client) end def _update_server_list() end end end end