1
2
3
4
5
6
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
public class Conversation {
private Gtk.Notebook conversations;
private Gtk.Widget widget;
private Gtk.TextView content;
private Gtk.Entry entry;
private string me;
private string jid;
private string display_name;
public signal void send_message(string type, string message);
private class TabLabel : Gtk.HBox {
public TabLabel(string label) {
pack_start(new Gtk.Label(label), false, true, 0);
Gtk.Button closeButton = new Gtk.Button();
Gdk.Pixbuf closeImage = render_icon(Gtk.STOCK_CLOSE, (Gtk.IconSize)(-1), null);
closeButton.image = new Gtk.Image.from_pixbuf(closeImage.scale_simple(16, 16, Gdk.InterpType.BILINEAR));
closeButton.height_request = 20;
closeButton.relief = Gtk.ReliefStyle.NONE;
pack_end(closeButton, false, false, 0);
show_all();
}
}
public Conversation(Gtk.Notebook conversations0, string me0, string jid0, string? display_name0, bool explicit = true) {
conversations = conversations0;
me = me0;
jid = jid0;
if(display_name0 != null)
display_name = display_name0;
else
display_name = jid;
Gtk.Builder builder = new Gtk.Builder();
try {
builder.add_objects_from_file("ephraim.glade", {"Conversation"});
} catch(Error e) {
}
widget = builder.get_object("Conversation") as Gtk.Widget;
content = builder.get_object("ConversationContent") as Gtk.TextView;
entry = builder.get_object("ConversationEntry") as Gtk.Entry;
entry.activate.connect((widget) => {
send_message("chat", entry.text);
entry.text = "";
});
unowned Gtk.Label title = builder.get_object("ConversationTitle") as Gtk.Label;
title.set_text("Conversation with " + display_name);
int page = conversations.append_page(widget, new TabLabel(display_name));
conversations.set_tab_reorderable(widget, true);
if(explicit)
conversations.page = page;
}
~Conversation() {
conversations.remove(widget);
}
public void sent_message(string type, string message) {
if(type != "chat")
return;
string str = me + ": " + message;
if(content.buffer.text.length != 0)
str = "\n" + str;
content.buffer.text += str;
}
public void receive_message(string type, string message) {
if(type != "chat")
return;
string str = display_name + ": " + message;
if(content.buffer.text.length != 0)
str = "\n" + str;
content.buffer.text += str;
}
}
|