1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
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.
9 require 'plugins/plugin'
11 require_bundle 'engines', 'find_exe'
18 AUTOLOADABLE_ENTRIES = {
19 'gnuchess' => { :name => 'GNU Chess',
21 :protocol => 'XBoard',
23 'crafty' => { :name => 'Crafty',
25 :protocol => 'XBoard',
27 'gnushogi' => { :name => 'GNU Shogi',
29 :protocol => 'GNUShogi',
31 'gpsshogi' => { :name => 'GPSShogi',
33 :protocol => 'GPSShogi',
34 :workdir => '/tmp' } }
38 attr_accessor :protocol
39 attr_accessor :workdir
41 attr_accessor :arguments
44 loader = PluginLoader.new
45 plugin = loader.get_all_matching(:engine).find do |e|
46 e.data(:protocol) == data[:protocol]
48 fact = lambda do |color, match|
49 plugin.new(@path, @name, color, match,
56 @game = Game.get(data[:game])
57 @protocol = data[:protocol]
58 @arguments = data[:arguments]
59 @workdir = data[:workdir]
63 def self.load(name, group)
64 entries = group.entry_map
65 entries['game'] ||= ''
67 :game => entries['game'].to_sym,
68 :path => entries['path'],
69 :protocol => entries['protocol'],
70 :arguments => entries['arguments'],
71 :workdir => entries['workdir']
75 group.write_entry('game', @game.class.data(:id).to_s)
76 group.write_entry('path', @path.to_s)
77 group.write_entry('protocol', @protocol.to_s)
78 group.write_entry('arguments', @arguments.to_s)
79 group.write_entry('workdir', @workdir.to_s)
83 plugin :name => 'Default Engine Loader',
84 :interface => :engine_loader
88 config = KDE::Global.config.group("Engines")
89 autoload unless config.exists
90 engine_groups = config.group_list
91 engine_groups.each do |engine_group|
92 entry = Entry.load(engine_group, config.group(engine_group))
93 @entries[entry.name] = entry
99 Entry::AUTOLOADABLE_ENTRIES.each do |keyword, data|
100 path = File.which(keyword)
102 data = data.merge(:path => path)
103 entries[data[:name]] = Entry.new(data)
106 update_entries(entries) unless entries.empty?
109 def update_entries(entries)
110 @entries = entries.dup
112 config = KDE::Global.config.group("Engines")
115 @entries.each do |name, engine|
116 group = config.group(name)
126 def find_by_game(game)
127 @entries.select do |name, e|