Class: LoginWindow

Inherits:
Gtk::Dialog
  • Object
show all
Includes:
ManqodCommon
Defined in:
lib/LoginWindow.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Method Summary collapse

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Constructor Details

#initialize(show_connections_combo = false) ⇒ LoginWindow

Returns a new instance of LoginWindow.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Method Details

#runObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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