#!/usr/bin/ruby -d # # erica # -- End user interface for RICA # NISHI Takao # # $Id: erica.rb,v 1.6 2001/11/11 07:48:57 zophos Exp $ # require 'gtk' require 'rica' require 'connectiondiag' require 'ctcpresponder' require 'logholder' include Rica ERICA_DEFAULT_TITLE='erica' ERICA_DEFAULT_TREE_WIDTH=100 ERICA_DEFAULT_TREE_HEIGHT=400 ERICA_DEFAULT_CLOG_WIDTH=400 ERICA_DEFAULT_CLOG_HEIGHT=250 ERICA_DEFAULT_WIDTH=500 ERICA_DEFAULT_HEIGHT=400 ################################################ # # Resouces # class Resouces include Singleton RESOUCE_SEARCH_PATH=[".",ENV["HOME"]] GTK_RESOUCE_FILE=".gtkrc" def initialize load @fontset=nil @tscolor=Gdk::Color.new(0,0,65535) @nickcolor=Gdk::Color.new(0,32767,0) @systemcolor=Gdk::Color.new(0,32767,0) @msgcolor=nil @bgcolor=nil end attr_accessor :fontset attr_accessor :tscolor attr_accessor :nickcolor attr_accessor :systemcolor attr_accessor :msgcolor attr_accessor :bgcolor def load RESOUCE_SEARCH_PATH.each{|path| f=path.to_s+"/"+GTK_RESOUCE_FILE if(FileTest::exist?(f)) Gtk::RC.parse(f) break end } end end ################################################ # # Servers, channels and users tree # (Gtk::Tree wrapper) # class BuffersTree0) addElement(*buf) end @contents[el]=Gtk::TreeItem.new(str) @contents[el].signal_connect('select'){|widget| begin @selection.each{|el| unless(el==widget) el.deselect end } @selection=[widget] @buffer.body.notify_signal(self,'select',*elements) rescue NameError end } @contents[el].signal_connect('deselect'){|widget| @selection.delete(widget) } @contents[el].show unless(@node.has_key?(node)) @node[node]=Gtk::Tree.new @node[node].set_selection_mode(Gtk::SELECTION_SINGLE) @contents[node].set_subtree(@node[node]) end @node[node].append(@contents[el]) end def removeChild(*elements) nd="/"+elements.join("/").downcase n=@node[nd] if(n.nil?) return end tag="^"+nd+"/" keys=@contents.keys keys.each{|i| if(i=~tag) if(@node.has_key?(i)) x=i.split("/") removeChild(*x) end begin n.remove_item(@contents[i]) rescue end @contents.delete(i) @contents.rehash end } @node.delete(nd) @node.rehash end def removeElement(*elements) removeChild(*elements) el="/"+elements.join("/").downcase elements.pop nd="/"+elements.join("/").downcase n=@node[nd] i=@contents[el] if((n.nil?)||(i.nil?)) return end n.remove_item(i) @contents.delete(el) @contents.rehash end def showElement(*elements) while(elements.size>0) el=getElement(*elements) unless(el.nil?) el.expand end elements.pop end end def refreshNames(server,channel) begin buf=@buffer[server][channel].namesArray el=getElement(server,channel) exp=nil if(el.instance_of?(Gtk::TreeItem)) exp=el.expanded? end removeChild(server,channel) buf.sort.each{|nick| addElement(server,channel,nick) } if(exp) el.expand end rescue NameError end end end ################################################ # # Common Log area # (Gtk::Text wrapper) # class LogAreaMAX_LOG_SIZE) if(@active&&(!freezing)) freezing=true @textarea.freeze end @textarea.delete_text(0,EXPIRE_LOG_SIZE) @textarea.set_point(@textarea.get_length) end if(@active&&freezing) @textarea.thaw end end end ################################################ # # Log buffer # (CommonLogArea and Gtk::Label wrapper) # # This class is used for log buffering # class LogBuffer=0) self.set_page(p) l.active=true l.refresh else l.bind(@buffer[@server][@channel]) l.active=true self.insert_page(l,nil,0) self.set_page(0) end end end def write(msg) if(msg.server.downcase==@server.to_s.downcase) begin if(msg.add_info.index(@channel.to_s.downcase)) if(msg.add_info.size>1) return nil else if(self.get_nth_page(self.get_current_page).scrolled?) return false else return true end end end rescue NameError return false end end return false end end ################################################ # # Entry Area # (Gtk::Entry wrapper and command parser) # class EntryArea