Class: Ig3tool::PrintenWindow

Inherits:
GladeHelper show all
Defined in:
lib/ui/printenwindow.rb

Defined Under Namespace

Classes: PrintUndo

Constant Summary collapse

["Printer", "Printen"]
ICON =
"stock_print.png"

Constants inherited from GladeHelper

GladeHelper::GLADE_DIR

Instance Method Summary collapse

Methods inherited from GladeHelper

#_get_widget, #add_window_colorer, #make_debugger_combo, #make_eval_widget, #make_status_combo, #present, #show

Constructor Details

#initializePrintenWindow

Returns a new instance of PrintenWindow.



35
36
37
38
39
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
66
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
# File 'lib/ui/printenwindow.rb', line 35

def initialize ()
	super("printen.glade")

	@notification = @glade.get_widget("notification")

	# PrintKrediet
	@credits_list = @glade.get_widget("credits_list")
	@user_entry = @glade.get_widget("user")
	@refund = @glade.get_widget("refund")

	# Username(PRIMARY), Email, Saldo, People_id
	model = Gtk::ListStore.new(String)
	renderer = Gtk::CellRendererText.new
	@credits_list.insert_column(-1, "Gebruiker", renderer) { |tvc, cell, m, iter|
		cell.text = iter[0].user
	}
	@credits_list.insert_column(-1, "Saldo", renderer) { |tvc, cell, m, iter|
		cell.text = sprintf("%.2f", iter[0].saldo)
	}
	@credits_list.insert_column(-1, "Categorie", renderer) { |tvc, cell, m, iter|
		cell.text = iter[0].price_category
	}
	@credits_list.insert_column(-1, "Email", renderer) { |tvc, cell, m, iter|
		cell.text = iter[0].email
	}

	filteredmodel = Gtk::TreeModelFilter.new(model)
	filteredmodel.set_visible_func do |model, iter|
		is_user_visible(iter[0].user)
	end
	@credits_list.model = filteredmodel

	_show_credits

	@window.show_all

	# PrintLog
	@log_refund = @glade.get_widget("log_refund")
	@log_list   = @glade.get_widget("log_list")

	# TODO - ADD JOBID IN DE LIJST VOOR REFUND!
	@log_list.model = Gtk::ListStore.new(String, String, String, String, String, String)
	# Meerdere selecteerbaar -> Grote refund indien nodig ;)
	@log_list.selection.mode = Gtk::SELECTION_MULTIPLE
	log_renderer = Gtk::CellRendererText.new
	log_renderer2 = Gtk::CellRendererText.new
	@log_list.insert_column(-1, "Uur", log_renderer) do |tvc, cell, m, iter|
		cell.text = iter[0].time.strftime('%a %H:%M')
	end
	@log_list.insert_column(-1, "User", log_renderer) do |tvc, cell, m, iter|
		cell.text = iter[0].user
	end
	@log_list.insert_column(-1, "Boodschap", log_renderer2) do |tvc, cell, m, iter|
		cell.text = iter[0].message
		cell.strikethrough = iter[0].refunded
	end
	_show_log

	@window.show_all

	@undo = PrintUndo.new

end

Instance Method Details

#activate_userObject



127
128
129
# File 'lib/ui/printenwindow.rb', line 127

def activate_user
	show_user @glade.get_widget("user").text
end

#delta_focus_outObject



144
145
146
147
# File 'lib/ui/printenwindow.rb', line 144

def delta_focus_out
	Ig3tool::number_eval_widget(@glade.get_widget("delta"))
	false
end

#errors_changedObject



136
137
138
# File 'lib/ui/printenwindow.rb', line 136

def errors_changed
	@credits_list.model.refilter
end

#focus_changedObject



131
132
133
134
# File 'lib/ui/printenwindow.rb', line 131

def focus_changed
	@notification.text = "" if @notification
	false
end

#is_user_visible(username) ⇒ Object



99
100
101
# File 'lib/ui/printenwindow.rb', line 99

def is_user_visible(username)
	username.include?(@user_entry.text) if @matcher.nil?
end

#list_row_activated(view, path, column) ⇒ Object



140
141
142
# File 'lib/ui/printenwindow.rb', line 140

def list_row_activated (view, path, column)
	show_user @credits_list.model.model.get_iter(path)[0].user
end

#log_list_cursor_changed(view) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/ui/printenwindow.rb', line 232

def log_list_cursor_changed (view)
	if selected = view.selection.selected
		printlog = selected[0]
		if @refund.sensitive = (printlog.message =~ /printed/)
			if !printlog.refunded
				@refund.label = "Terugbetalen"
			else
				@refund.label = "Toch betalen"
			end
		end
	end
end

#log_list_row_activated(view, path, column) ⇒ Object



249
250
251
252
# File 'lib/ui/printenwindow.rb', line 249

def log_list_row_activated (view, path, column)
	printlog = @log_list.model.get_iter(path)[0]
	show_user(printlog.user)
end

#refresh_clickedObject

PrintLog



227
228
229
230
# File 'lib/ui/printenwindow.rb', line 227

def refresh_clicked
	_show_credits
	_show_log
end

#refund_clickedObject



245
246
247
# File 'lib/ui/printenwindow.rb', line 245

def refund_clicked
	_refund_selection(@log_list.selection.select_all)
end

#show_user(username = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ui/printenwindow.rb', line 103

def show_user (username = nil)
	return if username.nil? or username.empty?

	begin
		user = $client.print_userinfo([ username ])

		@glade.get_widget('user').text = username # Kan username of alias zijn waarop men zoekt
		if user.nil?
			@glade.get_widget('saldo').text = '0'
			@glade.get_widget('email').text = "#{username}@vub.ac.be" # Klaarzetten om toe te voegen
			@glade.get_widget('status').active = 0
			@glade.get_widget('delta').grab_focus
		else
			@glade.get_widget('saldo').text = sprintf '%.2f', user.saldo
			@glade.get_widget('email').text = user.email
			@glade.get_widget('status').active = user.debugger? ? 1 : 0
			@glade.get_widget('delta').grab_focus
		end

	rescue Exception => e
		_print_msg "Fout: Userinfo: #{$!}"
	end
end

#toepassen_activate_cbObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ui/printenwindow.rb', line 204

def toepassen_activate_cb
	delta = @glade.get_widget("delta")
	Ig3tool::number_eval_widget(delta)
	amount = delta.text.to_i
	username = @glade.get_widget('user').text
	email = @glade.get_widget('email').text

	unless amount == 0
		begin
			# Indien de gebruiker nog niet bestaat, creeer automatisch een account wanneer er
			# op 'toevoegen krediet' wordt geklikt
			if !$client.print_userinfo([ username ])
				$client.print_addaccount!({ :username => username, :email => email })
			end
			answer = $client.print_addcredit!({ :username => username, :amount => amount })
			_print_msg "#{@user_entry.text} Gets #{amount} Credits"
		rescue Exception => e
			_print_msg "Fout: Toepassen: #{$!}"
		end
	end
end

#undo_activate_cbObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ui/printenwindow.rb', line 149

def undo_activate_cb
	# @Undo.method toont de LAATST GEBRUIKTE ACTIE aan
	case @undo.method
	when :adduser
		@undo.method = :none
		begin
			answer = $client.print_delaccount!({ :username => @undo.username })
			@undo.method = :deluser
		rescue Exception => e
			_print_msg "Fout: Undo: #{$!}"
		else
			_print_msg "Print Account #{@undo.username} werd verwijderd"
		end
	when :deluser
		@undo.method = :none
		begin
			answer = $client.print_addaccount!({ :username => @undo.username, :email => @undo.email, :amount => @undo.amount })
			@undo.method = :adduser
		rescue Exception => e
			_print_msg "Fout: Undo: #{$!}"
		else
			_print_msg "Print Account #{@undo.username} heraangemaakt met #{@undo.amount} krediet(en)!"
		end
	when :addcredit
		@undo.method = :none
		begin
			answer = $client.print_addcredit!({ :username => @undo.username, :email => @undo.email, :amount => - @undo.amount })
			@undo.method = :addcredit
			@undo.amount = - @undo.amount
		rescue Exception => e
			_print_msg "Fout: Undo: #{$!}"
		else
			_print_msg "Print Account #{@undo.username} werd veranderd met #{@undo.amount} krediet(en)"
		end
	when :refund
		@undo.method = :none
		begin
			_unrefund @undo.selection
		rescue Exception => e
			_print_msg "Fout: Undo: #{$!}"
		else
			_print_msg "Het terugbetalen van de Print Job (#{@undo.jobid}) van #{@undo.username} werd ongedaan gemaakt (#{@undo.amount} krediet(en))"
		end
	when :unrefund
		@undo.method = :none
		begin
			_refund @undo.selection
		rescue Exception => e
			_print_msg "Fout: Undo: #{$!}"
		else
			_print_msg "Het terugbetalen van de Print Job (#{@undo.jobid}) van #{@undo.username} werd uitgevoerd (#{@undo.amount} krediet(en))"
		end
	end
end