class LoginWindow

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Public Class Methods

new(show_connections_combo=false) click to toggle source
Calls superclass method
# File lib/LoginWindow.rb, line 7
def initialize(show_connections_combo=false)
        @curcon=nil
        super("manqod login",nil,nil,[Gtk::Stock::OK,Gtk::Dialog::RESPONSE_ACCEPT],[Gtk::Stock::QUIT,Gtk::Dialog::RESPONSE_REJECT])
        set_window_position(Gtk::Window::POS_CENTER)
        
        table=Gtk::Table.new(3,2,false)
        @conn_combo=Gtk::ComboBox.new(conn_model=Gtk::ListStore.new(String,String))
        if show_connections_combo
                table.attach(Gtk::Label.new('Connection'),0,1,0,1,Gtk::FILL,Gtk::FILL)
                table.attach(@conn_combo,1,2,0,1,Gtk::FILL|Gtk::EXPAND,Gtk::FILL|Gtk::EXPAND)
        end
        @conn_combo.pack_start(renderer=Gtk::CellRendererText.new,true).add_attribute(renderer,:text,0)
        table.attach(Gtk::Label.new('Username'),0,1,1,2,Gtk::FILL,Gtk::FILL)
        table.attach(@nick_entry=Gtk::Entry.new,1,2,1,2,Gtk::FILL|Gtk::EXPAND,Gtk::FILL|Gtk::EXPAND)
        table.attach(@passwd_label=Gtk::Label.new('Password'),0,1,2,3,Gtk::FILL,Gtk::FILL)
        table.attach(@passwd=Gtk::Entry.new.set_visibility(false),1,2,2,3,Gtk::FILL|Gtk::EXPAND,Gtk::FILL|Gtk::EXPAND)
        @passwd.signal_connect("activate") {|me|response(Gtk::Dialog::RESPONSE_ACCEPT)}
        @nick_entry.signal_connect("activate") {|me|response(Gtk::Dialog::RESPONSE_ACCEPT)}
        @conn_combo.signal_connect("changed"){|me|
                @curcon=ManqodRPC.instance.manqod_server.conn(@conn_combo.active_iter[1])
        }
        ManqodRPC.instance.manqod_server.conn_list{|conn_name,conn|
                begin
                        alive=ManqodRPC.instance.manqod_server.dbs[conn_name].alive?
                        rescue =>err
                        alive=false
                end
                if alive
              iter=conn_model.append
              iter[0]=conn["name"]
              iter[1]=conn_name
              if conn.has_key?("client_default") and conn["client_default"]==true
                                @conn_combo.set_active_iter(iter)
                        end
                end
        }


vbox.pack_start(table)
end

Public Instance Methods

run() click to toggle source
Calls superclass method
# File lib/LoginWindow.rb, line 48
def run
        show_all
        @nick_entry.grab_focus
        ret=nil
        while not (nick or ret==Gtk::Dialog::RESPONSE_REJECT)
                ret=super()
                if ret==Gtk::Dialog::RESPONSE_ACCEPT and !@curcon.nil?
                        #auth
                        np = Digest::MD5.new
                        np.update(@passwd.text)
                        if set_manqod_db_uri(@curcon['uri']) #"druby://#{@curcon['drb_host']}:#{@curcon['drb_port']}")
                                if @passwd.visible? then
                                        if ManqodDB.instance.manqod_db.auth?(@nick_entry.text,np.hexdigest)
                                                set_nick(@nick_entry.text)
                                        else
                                                errwin=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,Gtk::MessageDialog::ERROR,Gtk::MessageDialog::ButtonsType::CLOSE,"login failed!");errwin.run;errwin.destroy
                                        end
                                else
                                        set_nick(@nick_entry.text)
                                end
                        else
                                errwin=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,Gtk::MessageDialog::ERROR,Gtk::MessageDialog::ButtonsType::CLOSE,"connecting to server #{@curcon['name']} failed!");errwin.run;errwin.destroy
                        end
                end
        end
        hide_all
        nick
end