Class: Ig3tool::InterneWindow

Inherits:
GladeHelper show all
Includes:
GetText
Defined in:
lib/ui/interne.rb

Constant Summary collapse

["Interne", "Interne"]
ICON =
"piggy_xsmall.png"

Constants inherited from GladeHelper

GladeHelper::GLADE_DIR

Instance Method Summary collapse

Methods inherited from GladeHelper

#_get_widget, #add_window_colorer, #load_sounds, #make_debugger_combo, #make_eval_widget, #make_status_combo, #number_eval_widget, #play, #present, #show, #speak

Constructor Details

#initializeInterneWindow

Returns a new instance of InterneWindow.



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
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ui/interne.rb', line 14

def initialize
  super("newinterne.glade")


  @action = @glade.get_widget("action")
  @notification = @glade.get_widget("notification")
  @message = @glade.get_widget("message")
  @amount = @glade.get_widget("amount")
  @saldo = @glade.get_widget("saldo")
  @from = @glade.get_widget("fromcombo")
  @to = @glade.get_widget("tocombo")

  @transactions = @glade.get_widget("transactions")
  @transactions.model = @transactions_store = Gtk::ListStore.new(Object, String, String, String, String, String)
  l = Gtk::CellRendererText.new
  @transactions.insert_column(-1, "time", l) do |tvc, cell, m, iter|
cell.text = Time.parse(iter[0].time).strftime("%d/%m/%y")
  end
  @transactions.insert_column(-1, "amount", l) do |tvc, cell, m, iter|
    cell.text = iter[0].amount.from_c.to_s
  end
  @transactions.insert_column(-1, "from", l) do |tvc, cell, m, iter|
    cell.text = iter[0].donor
  end
  @transactions.insert_column(-1, "to", l) do |tvc, cell, m, iter|
    cell.text = iter[0].recipient
  end
  @transactions.insert_column(-1, "message", l) do |tvc, cell, m, iter|
    cell.text = iter[0].message
  end

  add_window_colorer(@from, @window)

  @amount.text = "0.0"
  #@window.signal_connect("activate-focus") do
  #  @notification.text = "refreshing..."
  #  _update_debuggers
  #  @notification.text = "refresh done"
  #end

  _update_debuggers
  _update_transactions

end

Instance Method Details

#fromchange(widget) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ui/interne.rb', line 79

def fromchange(widget)
  setaction(@from.active, @to.active)
  fromusername = @internes[@from.active-1].username
  if @from.active != 0
    interne = $client.interne(fromusername)
    @saldo.text = interne.saldo.from_c.to_s
  end
  @saldo.text = "unlimited moneyz" if @from.active == 0
  if @from.active == 0
    _update_transactions
  else
    fromusername = @internes[@from.active - 1].username 
    _update_transactions(fromusername)
  end
end

#refresh(widget) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ui/interne.rb', line 59

def refresh(widget)
  from = @from.active
  fromusername = @internes[from-1].username
  setaction(from, @to.active)
  _update_debuggers_nothread
  @from.active = from
  puts "DEBUG: #{fromusername}"
  interne = $client.interne(fromusername)
  @saldo.text = interne.saldo.from_c.to_s unless from == 0
  @saldo.text = "unlimited moneyz" if from == 0
  if from == 0
    _update_transactions
  else
    _update_transactions(fromusername)
  end
end

#setaction(from, to) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ui/interne.rb', line 118

def setaction(from, to)
  if from == 0
    fromusername = "kas"
  else
    fromusername = @internes[from-1].username 
  end
  if to == 0
    tousername = "kas"
  else
    tousername = @internes[to-1].username
  end
  @action.set_markup("toss money from <b>#{fromusername}</b> to <b>#{tousername}</b>")
  @action.set_markup("retract money from kas") if fromusername == "kas"
  @action.set_markup("deposit money to your interne") if tousername == "kas"
  @action.set_markup("money masturbation detected!") if from == to
end

#tochange(widget) ⇒ Object



76
77
78
# File 'lib/ui/interne.rb', line 76

def tochange(widget)
  setaction(@from.active, @to.active)
end

#tossmoney(widget) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ui/interne.rb', line 94

def tossmoney(widget)
  if @from.active == 0
    fromusername = "kas"
  else
    fromusername = @internes[@from.active-1].username 
  end
  if @to.active == 0
    tousername = "kas"
  else
    tousername = @internes[@to.active-1].username
  end
  begin
    amount = @amount.text
    raise Ig3tool::IG3Error, "uncorrect format for amount" unless amount =~ /\d+(\.\d{1,2}){0,1}/
    message = @message.text.strip
    message = "No message" if message.nil? or message.empty?
    $client.interne_transfer!("from" => fromusername, "to" => tousername, "amount" => @amount.text.strip.to_c, "message" => message) 
    _clear
    _update_transactions(fromusername)
    @notification.text = "transferred #{amount} EUR from #{fromusername} to #{tousername}"
  rescue Exception => e
    @notification.text = e.message
  end
end