Class: ConfStorage

Inherits:
Object
  • Object
show all
Includes:
Eprint, Singleton
Defined in:
lib/Common/Conf.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 Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Method Summary collapse

Methods included from Eprint

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

Instance Method Details

#conf_valuesObject



26
27
28
# File 'lib/Common/Conf.rb', line 26

def conf_values
		@myconf
end

#get_conf(i, j, k) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/Common/Conf.rb', line 9

def get_conf(i,j,k)
	if !@myconf.nil?
		if @myconf[i.to_s]
			if @myconf[i.to_s][j.to_s]
				@myconf[i.to_s][j.to_s][k.to_s]
			end
		end
	end
end

#load_confObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/Common/Conf.rb', line 67

def load_conf
	@myconf=Hash.new# if @myconf.nil?
	@myinitconf=Hash.new# if @myinitconf.nil?
	sql="select * from conf where nick='#{Nick.instance.get_nick}'"
	ManqodDB.instance.manqod_db.admin.rows("select * from conf where nick='#{Nick.instance.get_nick}'").each{|row|
			set_conf(row["moditemid"].to_s,row["itemid"].to_s,row["Variable"].to_s,row["Value"].to_s)
			set_conf(row["moditemid"].to_s,row["itemid"].to_s,row["Variable"].to_s,row["Value"].to_s,@myinitconf)
			if Eprint::DOMAIN.has_key?(row["Variable"].to_s)
				Eprint::DOMAIN[row["Variable"]]=row["Value"]
			end
	}
	set_conf(0,0,"button-size","gtk-small-toolbar") if !get_conf(0,0,"button-size")
	set_conf(0,0,"menu-type","standard") if !get_conf(0,0,"menu-type")
	set_conf(0,0,"menu-position","top") if !get_conf(0,0,"menu-position")
	set_conf(0,0,"grid","both") if !get_conf(0,0,"grid")
	set_conf(0,0,"form-grid","none") if !get_conf(0,0,"form-grid")
	set_conf(0,0,"list-tooltip","false") if !get_conf(0,0,"list-tooltip")

	set_conf(0,0,"info-frame-font","Verdana 10") if !get_conf(0,0,"info-frame-font")
	set_conf(0,0,"info-item-font","Verdana Bold 10") if !get_conf(0,0,"info-item-font")
	set_conf(0,0,"form-frame-font","Verdana Bold 10") if !get_conf(0,0,"form-frame-font")
	set_conf(0,0,"form-item-font","Verdana 10") if !get_conf(0,0,"form-item-font")

	set_conf(0,0,"list-button-font","Verdana 10") if !get_conf(0,0,"list-button-font")
	set_conf(0,0,"list-cell-font","Verdana 10") if !get_conf(0,0,"list-cell-font")

	set_conf(0,0,"bar-menu-font","Verdana 10") if !get_conf(0,0,"bar-menu-font")

	set_conf(0,0,"confirm-exit","true") if !get_conf(0,0,"confirm-exit")
	set_conf(0,0,"last-viewed-message",0) if !get_conf(0,0,"last-viewed-message")

end


30
31
32
33
34
35
36
37
38
# File 'lib/Common/Conf.rb', line 30

def print_conf(conf=@myconf)
		conf.each{|ik,iv|
		iv.each{|jk,jv|
 			jv.each{|kk,kv|
				print "[",ik,",",jk,",",kk,"]=",kv,"\n"
 			}
		}
		}
end

#save_confObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/Common/Conf.rb', line 40

def save_conf
		return false if Nick.instance.get_nick.nil?
		edebug("saving settings for #{Nick.instance.get_nick}","config","info")
		scount=0
		begin
		@myconf.each{|ik,iv|
		iv.each{|jk,jv|
 			jv.each{|kk,kv|
				if @myinitconf.has_key?(ik) && @myinitconf[ik].has_key?(jk) && @myinitconf[ik][jk].has_key?(kk)
  				needtosave=@myinitconf[ik][jk][kk] != @myconf[ik][jk][kk]
				else
  				needtosave=true
				end
				if needtosave
		  			sql="replace into conf set nick='#{Nick.instance.get_nick}', Variable='#{kk}', moditemid='#{ik}', itemid='#{jk}',  Value='#{ManqodDB.instance.manqod_db.admin.escape_string(kv)}'"
		  			ManqodDB.instance.manqod_db.admin.query(sql)
  				scount=scount+1
				end
 			}
		}
		}
		edebug("#{scount} changed settings saved","config","normal")
		rescue =>err
			edebug("can't save user configs, #{err}","config","error")
		end
end

#set_conf(moditem_id, item_id, variable, value, conf = @myconf) ⇒ Object



19
20
21
22
23
24
# File 'lib/Common/Conf.rb', line 19

def set_conf(moditem_id,item_id,variable,value,conf=@myconf)
	edebug("#{moditem_id}:#{item_id}:#{variable} => #{value}","config","info")
	conf[moditem_id.to_s]=Hash.new if !conf.has_key?(moditem_id.to_s)
	conf[moditem_id.to_s][item_id.to_s]=Hash.new if !conf[moditem_id.to_s].has_key?(item_id.to_s)
	conf[moditem_id.to_s][item_id.to_s][variable.to_s]=value.to_s
end