Skip to content

Commit

Permalink
ON & OD
Browse files Browse the repository at this point in the history
git-svn-id: file:///comboy/svn/onim/trunk@3 ddd93275-964d-42a2-867a-75629c878e58
  • Loading branch information
comboy committed Dec 4, 2008
1 parent a7c2be4 commit c31c3e2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
13 changes: 11 additions & 2 deletions lib/onim/base.rb
Expand Up @@ -2,9 +2,10 @@ module Onim
class Base

def initialize
@logger = Logger.new File.join(Onim::PATH,"test.log")
@engine = Engine.new self
@gui = Gui.new self
#@engine.connect
@engine.connect
@gui.show
end

Expand All @@ -20,5 +21,13 @@ def message_received(jid,text)
def send_message(jid,text)
@engine.send_message jid,text
end

def item_presence_change(jid,presence,status)
@gui.item_presence_change(jid,presence,status)
end

def debug(text)
@logger.info text
end
end
end
end
33 changes: 30 additions & 3 deletions lib/onim/engine.rb
@@ -1,9 +1,12 @@

require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/roster'

module Onim
class Engine

attr_accessor :base

include Jabber
#Jabber::debug = true

Expand All @@ -23,13 +26,17 @@ def connect

puts "setting up.."
cl = Client.new(JID::new('kompotek@jabster.pl'))
#cl = Client.new(JID::new('comboy@softwarelab.eu'))
@client = cl
puts "connect"
cl.connect
puts "auth"
cl.auth 'bociankowo'
#cl.auth 'spoczko'
puts "done"
cl.send(Presence.new.set_type(:available))




#cl.presence_updates do |friend, old_presence, new_presence|
# puts "Received presence update from #{friend.to_s}: #{new_presence}"
Expand All @@ -42,6 +49,25 @@ def connect


@roster = Roster::Helper.new cl

@roster.add_presence_callback do |item,oldpres,pres|
pres = Presence.new unless pres
oldpres = Presence.new unless oldpres


base.debug "presence change: #{pres.from} : #{pres.type.inspect} #{pres.status.to_s}"
base.debug "mmmmmmmm #{pres.show} ===== #{pres.priority} <"
pres = oldpres
base.debug "OLD presence change: #{pres.from} : #{pres.type.inspect} #{pres.status.to_s}"
base.debug "OLD mmmmmmmm #{pres.show} ===== #{pres.priority} <"

status = pres.status
presence = pres.show.to_sym || :available
# XXX unavaliable
presence = :unavailable if pres.status.to_s == 'unavailable'
base.item_presence_change(pres.from,presence,status)
end

mainthread = Thread.current

@roster.add_query_callback { |iq|
Expand Down Expand Up @@ -89,6 +115,7 @@ def connect
end
Thread.stop
#pp @roster.items
cl.send(Presence.new.set_type(:available))

rescue Exception => e
puts e
Expand All @@ -97,4 +124,4 @@ def connect
end
end
end
end
end
64 changes: 47 additions & 17 deletions lib/onim/gui.rb
Expand Up @@ -9,7 +9,7 @@ class Gui

def initialize(base)
@base = base

debug "GUI intialization"
# Load main window
@glade = GladeXML.new(Onim::PATH+'gui/main.glade', nil, 'window_main')
@main = @glade['window_main']
Expand All @@ -21,23 +21,37 @@ def initialize(base)
# Load contacts lists and create columns
@contacts = @glade['treeview_contacts']
%w{Icon Contact}.each_with_index do |name,index|
renderer = Gtk::CellRendererText.new
if name == 'Icon'
renderer = Gtk::CellRendererPixbuf.new
@contacts.append_column(Gtk::TreeViewColumn.new(name, renderer, :pixbuf => index+1, 'background-gdk' => 7))
else
renderer = Gtk::CellRendererText.new
@contacts.append_column(Gtk::TreeViewColumn.new(name, renderer, :text => index+1, 'background-gdk' => 7))
end
#renderer.font = "bold" if index == 5
@contacts.append_column(Gtk::TreeViewColumn.new(name, renderer, :text => index+1, 'background-gdk' => 7))
end
@contacts.signal_connect('row-activated') {
|view,path,column| contact_click @contacts.model.get_iter(path)
|view,path,column| contact_click @contacts.model.get_iter(path)[0]

}

# Load status select
@status_select = @glade['combobox_status']
# renderer = Gtk::CellRendererText.new
# @status_select.append_column(Gtk::TreeViewColumn.new('wow', renderer, :text => 0))
available_statuses = Gtk::TreeStore.new(String)
%w{Dostępny Zajęty Niedostępny}.each do |item|
x = available_statuses.append nil
x.set_value(0,item)
end
@status_select.model = available_statuses
@status_select.set_active 0

@message_windows = {}
end

def show
@main.show
#sm
set_roster_items []
Gtk.main
end

Expand All @@ -48,6 +62,9 @@ def sm
def contact_click(contact)
puts "contact click"
pp contact
jid = contact[:jid]
jid = jid.split('/')[0]
window = message_window_for(jid)
end

def message_window_for(jid)
Expand All @@ -58,14 +75,17 @@ def message_window_for(jid)
end

def message_received(jid,text)
puts "GUI: message received from #{jid}"
debug "GUI: message received from #{jid}"
jid = jid.split('/')[0]
window = message_window_for(jid)
pp @contacts_data
jid = jid.split('/')[0]
puts "add msg"
@message_windows[jid].add_message(text)
debug "add msg"
window.add_message(text)
end

def item_presence_change(jid,presence,status)

end
#
# items:
# { :name => 'John',
Expand All @@ -75,22 +95,32 @@ def message_received(jid,text)
def set_roster_items(items)
@contacts_data = {}

contacts_model = Gtk::TreeStore.new(Hash,String,String,Symbol)
contacts_model = Gtk::TreeStore.new(Hash,Gdk::Pixbuf,String,Symbol)
#issues = []
#issues = redmine.project_issues project_id, @assignee_filter, @status_filter
items = [{:name => 'ueoau', :jid => 'ueoueo'},{:name => 'ueoa', :jid => 'euooeu'}]
#pp issues
#items = [{:name => 'ueoau', :jid => 'ueoueo'},{:name => 'ueoa', :jid => 'euooeu'}]
#pp issues
items.each do |item|
@contacts_data[item[:jid]] = item
status = :unavailable
x = contacts_model.append nil
x.set_value(0,{})
x.set_value(1,'o')
x.set_value(0,item)
image = case status
when :unavailable then 'user_offline.gif'
when :online then 'user_online.gif'
else 'user_dnd.gif'
end
x.set_value(1,Gdk::Pixbuf.new(Onim::PATH+'gui/images/'+image))
x.set_value(2,item[:name])
x.set_value(3,:unavailable)
x.set_value(3,status)
# @contacts.model.insert(nil,@contacts.model.iter_first,[{},'ueoa','euee','aaaa'])
end

@contacts.model = contacts_model
end

def debug(text)
base.debug(text)
end
end
end
end

0 comments on commit c31c3e2

Please sign in to comment.