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'
10 require 'action_provider'
11 require_bundle 'ics', 'config'
12 require_bundle 'ics', 'connection'
13 require_bundle 'ics', 'match_handler'
14 require_bundle 'ics', 'preferences'
15 require_bundle 'ics', 'protocol'
16 require_bundle 'ics', 'status_observer'
20 include ActionProvider
28 if not @main or @main.closed?
29 @main = create(:name => 'ICS')
34 def create(opts = { })
38 def activate(user, name)
39 @view.activate(user, name)
43 plugin :name => 'ICS Plugin',
44 :interface => :action_provider
49 @gui = KDE::gui(:icsplugin) do |g|
52 m.action :connect, :group => :file_extensions
53 m.action :disconnect, :group => :file_extensions
55 mb.menu(:settings) do |m|
56 m.action :configure_ics
59 g.tool_bar(:ics_toolbar, :text => KDE::i18n("&ICS Toolbar")) do |tb|
66 :text => KDE.i18n("&Connect to ICS"),
67 :icon => 'network-connect') do |parent|
68 connect_to_ics(parent)
71 :text => KDE.i18n("&Disconnect from ICS"),
72 :icon => 'network-disconnect') do |parent|
77 parent.console.delete_observer(@console_obs)
82 action(:configure_ics,
83 :icon => 'network-workgroup',
84 :text => KDE.i18n("Configure &ICS...")) do |parent|
85 dialog = ICS::Preferences.new(parent)
90 def connect_to_ics(parent)
91 protocol = ICS::Protocol.new(false)
92 @connection = ICS::Connection.new('freechess.org', 23)
94 config = ICS::Config.load
95 protocol.add_observer ICS::AuthModule.new(@connection,
96 config[:username], config[:password])
97 protocol.add_observer ICS::StartupModule.new(@connection)
98 protocol.link_to(@connection)
100 status_observer = StatusObserver.new(
101 lambda {|msg| parent.status_bar.show_message(msg, 2000) },
102 lambda {|msg| parent.status_bar.show_permanent_message(msg) })
103 status_observer.link_to(@connection, protocol)
105 protocol.on :text do |text|
106 parent.console.append(text)
109 @console_obs = parent.console.observe :input do |text|
111 @connection.send_text text
116 @view = ICSView.new(parent.view)
117 @handler = ICS::MatchHandler.new(@view, protocol)