Class: MyFileChooserButton

Inherits:
Gtk::FileChooserWidget
  • Object
show all
Includes:
Conf, ManqodCommon
Defined in:
lib/FormHolder/Form/InputHolder/FileChooser.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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conf

#get_conf, #load_conf, #save_conf, #set_conf

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(pc) ⇒ MyFileChooserButton

Returns a new instance of MyFileChooserButton.



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
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 8

def initialize(pc)
	@pc=pc
	action=case item['action']
		when 'load' then Gtk::FileChooser::Action::OPEN
		when 'save' then Gtk::FileChooser::Action::SAVE
	end
	super(action)
#	 set_select_multiple(false)
	path=get_conf(0,item['id'],"path")
	set_current_folder(path) if !path.nil?

	preview=Gtk::Image.new
	set_preview_widget(preview)
	signal_connect("update-preview") {
		filename = preview_filename
		begin
			have_pixbuf=true
			pixbuf = Gdk::Pixbuf.new(filename, 128, 128)
			rescue
				have_pixbuf=false
		end
		preview_widget.set_pixbuf(pixbuf)
		set_preview_widget_active(have_pixbuf)
	}
	begin
		@ftp=eval(pc.gtk_attribute("ftp-access").to_s)
	rescue =>err
		ewarn(err)
	end
	pack_start(@progress=Gtk::ProgressBar.new,false,true,1) if @ftp.class==Array
end

Instance Attribute Details

#ftpObject

Returns the value of attribute ftp.



39
40
41
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 39

def ftp
  @ftp
end

#pcObject

Returns the value of attribute pc.



39
40
41
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 39

def pc
  @pc
end

#progressObject

Returns the value of attribute progress.



39
40
41
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 39

def progress
  @progress
end

Instance Method Details

#ftp_getObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 100

def ftp_get
	unless @ftp.class==Array
		warn("no ftp access defined")
		return false
	end
	set_conf(0,item['id'],"path",current_folder)
 	ftp=Net::FTP.new(@ftp[0],@ftp[1],@ftp[2])
 	@ftp[3].each("/"){|s|
		einfo("changing ftp dir: #{s}","form")
		ftp.chdir(s)
	} if @ftp[3]
 	perc=0
 	einfo(item["initial"],"form")
 	ftp.getbinaryfile(item["initial"],filename,ftp.size(item["initial"])/100){
 		progress.set_fraction(perc/100.0)
 		Gtk.show_thread_changes
 		perc+=1
 	}
 	ftp.close
end

#ftp_storeObject



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/FormHolder/Form/InputHolder/FileChooser.rb', line 74

def ftp_store
	unless @ftp.class==Array
		warn("no ftp access defined")
		return false
	end
	set_conf(0,item['id'],"path",current_folder)
 	ftp=Net::FTP.new(@ftp[0],@ftp[1],@ftp[2])
 	@ftp[3].each("/"){|s|
		begin
			einfo("changing ftp dir: #{s}","form")
			ftp.chdir(s)
		rescue =>err
			einfo("creating ftp dir: #{s}","form")
			ftp.mkdir(s)
			retry
		end
	} if @ftp[3]
 	perc=0
 	ftp.putbinaryfile(filename,text,File.size(filename)/100){
 		progress.set_fraction(perc/100.0)
 		Gtk.show_thread_changes
 		perc+=1
 	}
 	ftp.close
end

#itemObject



41
42
43
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 41

def item
	@pc.item
end

#loadObject



56
57
58
59
60
61
62
63
64
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 56

def load
	ret=String.new
	file = File.new(filename, "rb")
	ret=file.read
	file.close
	edebug("loaded","list-filechooser","debug")
	set_conf(0,item['id'],"path",current_folder) 
	ret
end

#loadPixbufObject



122
123
124
125
126
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 122

def loadPixbuf
	set_conf(0,item['id'],"path",current_folder) 
	pixdata=Gdk::Pixdata.from_pixbuf(Gdk::Pixbuf.new(filename),true)
	pixdata.serialize.pack("c*")
end

#save(content) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 66

def save(content)
	file = File.new(filename, "wb+")
	file.write(content)
	file.close
	edebug("saved","list-filechooser","debug")
	set_conf(0,item['id'],"path",current_folder) 
end

#textObject



52
53
54
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 52

def text
	filename[current_folder.length() +1 .. filename.length()]
end

#update(nfilename = item['default']) ⇒ Object



45
46
47
48
49
50
# File 'lib/FormHolder/Form/InputHolder/FileChooser.rb', line 45

def update(nfilename=item['default'])
	run_events(item['id'],'info_item-BeforeUpdate')
	edebug("filename to set: |#{nfilename}|","list-filechooser","debug")
	set_current_name(nfilename) if nfilename
	run_events(item['id'],'info_item-AfterUpdate')
end