Add action list support to qtonly.
[kaya.git] / lib / games / game_actions.rb
blobc197375a65d5a610ac4bc44b8dd91de36c599be6
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'toolkit'
9 require 'action_provider'
11 module GameActions
12   include ActionProvider
13   
14   def actions(parent, collection, policy)
15     actions = (@action_data || []).map{|data| create_action(data, parent, collection, policy) }
16     actions
17   end
18   
19   def create_action(data, parent, collection, policy)
20     icon = if data.opts[:icon]
21       KDE::Icon.new(data.opts[:icon])
22     else
23       KDE::Icon.new
24     end
25     text = data.opts[:text] || data.id.to_s
26     a = KDE::Action.new(icon, text, parent)
27     collection[data.id] = a
28     if data.opts.has_key?(:checked)
29       a.checkable = true
30       a.checked = data.opts[:checked]
31       a.connect(SIGNAL('toggled(bool)')) do |value|
32         data.action[value, policy]
33       end
34     else
35       a.on(:triggered) { data.action[policy] }
36     end
37     a
38   end
39 end