All plugins load by themselves now.
[kaya.git] / lib / plugins / ics / ics.rb
blob5ae7d5cb3c734eacdeb5f909adf1ed9469652c26
1 require 'qtutils'
2 require 'plugins/plugin'
3 require 'require_bundle'
4 require 'action_provider'
5 require_bundle 'ics', 'protocol'
6 require_bundle 'ics', 'connection'
7 require_bundle 'ics', 'match_handler'
9 class ICSPlugin
10   include Plugin
11   include ActionProvider
12   
13   plugin :name => 'ICS Plugin',
14          :interface => :action_provider,
15          :bundle => 'ics'
16          
17   def initialize
18     action(:connect,
19            :text => KDE.i18n("&Connect to ICS"),
20            :icon => 'network-connect') do |parent|
21       connect_to_ics(parent)
22     end
23     action(:disconnect,
24            :text => KDE.i18n("&Disconnect from ICS"),
25            :icon => 'network-disconnect') do |parent|
26       if @connection
27         @connection.close
28         @connection = nil
29       end
30     end
31   end
32   
33   def connect_to_ics(parent)
34     protocol = ICS::Protocol.new(:debug)
35     @connection = ICS::Connection.new('freechess.org', 23)
36     config = KDE::Global.config.group("ICS")
37     protocol.add_observer ICS::AuthModule.new(@connection, 
38       config.read_entry('username', 'guest'), 
39       config.read_entry('password', ''))
40     protocol.add_observer ICS::StartupModule.new(@connection)
41     protocol.link_to @connection
43     protocol.observe :text do |text|
44       parent.console.append(text)
45     end
47     parent.console.observe :input do |text|
48       @connection.send_text text
49     end
51     @handler = ICS::MatchHandler.new(parent.controller, 
52                                     protocol)
54     @connection.start
55   end
56 end