Class: Messaging::MessageReader

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/SB/Messaging.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessageReader

Returns a new instance of MessageReader.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/SB/Messaging.rb', line 7

def initialize
	super()
	set_size_request(400,300)
	set_window_position(Gtk::Window::Position::CENTER_ON_PARENT)
	set_transient_for(SB.instance.parent_window)
	set_modal(true)
	set_title("Message Reader")
	@mmodel=Gtk::ListStore.new(String,String,String,String,String,String,String)
	@sorter=Gtk::TreeModelSort.new(@mmodel).set_sort_column_id(0,Gtk::SortType::DESCENDING)
	add(Gtk::VPaned.new.
		set_position(170).set_position_set(true).
		add1(Gtk::ScrolledWindow.new.
			set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC).
			add(@list=Gtk::TreeView.new(@sorter))
		).
		add2(Gtk::ScrolledWindow.new.
			set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC).
			add_with_viewport(@body=Gtk::TextView.new)
		)
	)
	list.append_column(Gtk::TreeViewColumn.new("Date",renderer=Gtk::CellRendererText.new, {:text => 0,:font => 4}).set_sort_column_id(0))
	list.append_column(Gtk::TreeViewColumn.new("Sender",renderer=Gtk::CellRendererText.new, {:text => 1,:font => 4}).set_sort_column_id(1))
	list.append_column(Gtk::TreeViewColumn.new("Subject",renderer=Gtk::CellRendererText.new, {:text => 2,:font => 4}).set_sort_column_id(2))
	list.signal_connect("cursor-changed"){|me|
		if me.cursor
			item=@sorter.get_iter(me.cursor[0])
			si=@sorter.convert_iter_to_child_iter(item)
			@body.buffer.delete(@body.buffer.bounds[0],@body.buffer.bounds[1])
			@body.buffer.insert_at_cursor(si[5])
			if si[3] == "n"
				begin
					ManqodDB.instance.manqod_db.set_message_read(item[6],Nick.instance.get_nick)
				rescue => err
					ewarn("Can't set message read for all clients")
				end
				si[3]="n"
				si[4]="Verdana 10"
			end
		end
	}

end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



49
50
51
# File 'lib/SB/Messaging.rb', line 49

def body
  @body
end

#listObject (readonly)

Returns the value of attribute list.



49
50
51
# File 'lib/SB/Messaging.rb', line 49

def list
  @list
end

Instance Method Details

#populateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/SB/Messaging.rb', line 50

def populate
	@mmodel.clear
	begin
		ManqodDB.instance.manqod_db.messages(Nick.instance.get_nick).each{|message|
			i=@mmodel.append
			i[0]=message["date"]
			i[1]=message["sender"]
			i[2]=message["subject"]
			i[3]=message["state"]
			i[4]=(message["state"] == "n" ? "Verdana Bold 10" : "Verdana 10")
			i[5]=message["body"]
			i[6]=message["id"]
		}
	rescue => err
		ewarn("Can't read messages from server")
	end
	self
end