2020-02-21 01:11:23 +00:00
|
|
|
using Gee;
|
|
|
|
using Gdk;
|
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
namespace Dino.Ui {
|
|
|
|
|
|
|
|
enum Target {
|
|
|
|
URI_LIST,
|
|
|
|
STRING
|
|
|
|
}
|
|
|
|
|
|
|
|
const TargetEntry[] target_list = {
|
|
|
|
{ "text/uri-list", 0, Target.URI_LIST }
|
|
|
|
};
|
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
public class ConversationViewController : Object {
|
2020-02-21 01:11:23 +00:00
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
public new string? conversation_display_name { get; set; }
|
|
|
|
public string? conversation_topic { get; set; }
|
|
|
|
|
|
|
|
private Application app;
|
|
|
|
private ConversationView view;
|
|
|
|
private ConversationTitlebar titlebar;
|
|
|
|
public SearchMenuEntry search_menu_entry = new SearchMenuEntry();
|
2020-02-21 01:11:23 +00:00
|
|
|
|
|
|
|
private ChatInputController chat_input_controller;
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
private Conversation? conversation;
|
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
public ConversationViewController(ConversationView view, ConversationTitlebar titlebar, StreamInteractor stream_interactor) {
|
|
|
|
this.view = view;
|
|
|
|
this.titlebar = titlebar;
|
2020-02-21 01:11:23 +00:00
|
|
|
this.stream_interactor = stream_interactor;
|
2020-02-21 01:42:19 +00:00
|
|
|
this.app = GLib.Application.get_default() as Application;
|
2020-02-21 01:11:23 +00:00
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
this.chat_input_controller = new ChatInputController(view.chat_input, stream_interactor);
|
2020-02-21 01:11:23 +00:00
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
view.conversation_frame.init(stream_interactor);
|
2020-02-21 01:11:23 +00:00
|
|
|
|
|
|
|
// drag 'n drop file upload
|
2020-02-21 01:42:19 +00:00
|
|
|
Gtk.drag_dest_unset(view.chat_input.text_input);
|
|
|
|
Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY);
|
|
|
|
view.drag_data_received.connect(this.on_drag_data_received);
|
2020-02-21 01:11:23 +00:00
|
|
|
|
|
|
|
// forward key presses
|
2020-02-21 01:42:19 +00:00
|
|
|
view.chat_input.key_press_event.connect(forward_key_press_to_chat_input);
|
|
|
|
view.conversation_frame.key_press_event.connect(forward_key_press_to_chat_input);
|
|
|
|
titlebar.key_press_event.connect(forward_key_press_to_chat_input);
|
2020-02-21 01:11:23 +00:00
|
|
|
|
|
|
|
// goto-end floating button
|
2020-02-21 01:42:19 +00:00
|
|
|
var vadjustment = view.conversation_frame.scrolled.vadjustment;
|
2020-02-21 01:11:23 +00:00
|
|
|
vadjustment.notify["value"].connect(() => {
|
2020-02-21 01:42:19 +00:00
|
|
|
view.goto_end_revealer.reveal_child = vadjustment.value < vadjustment.upper - vadjustment.page_size;
|
|
|
|
});
|
|
|
|
view.goto_end_button.clicked.connect(() => {
|
|
|
|
view.conversation_frame.initialize_for_conversation(conversation);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update conversation display name & topic
|
|
|
|
this.bind_property("conversation-display-name", titlebar, "title");
|
|
|
|
this.bind_property("conversation-topic", titlebar, "subtitle");
|
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).room_name_set.connect((account, jid, room_name) => {
|
|
|
|
if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) {
|
|
|
|
update_conversation_display_name();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => {
|
|
|
|
if (conversation != null && conversation.counterpart.equals_bare(room.bare_jid) && conversation.account.equals(account)) {
|
|
|
|
update_conversation_display_name();
|
|
|
|
}
|
2020-02-21 01:11:23 +00:00
|
|
|
});
|
2020-02-21 01:42:19 +00:00
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => {
|
|
|
|
if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) {
|
|
|
|
update_conversation_topic(subject);
|
|
|
|
}
|
2020-02-21 01:11:23 +00:00
|
|
|
});
|
2020-02-21 01:42:19 +00:00
|
|
|
|
2020-02-22 02:00:55 +00:00
|
|
|
// Headerbar plugins
|
2020-02-21 01:42:19 +00:00
|
|
|
app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor));
|
|
|
|
app.plugin_registry.register_contact_titlebar_entry(search_menu_entry);
|
|
|
|
app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor));
|
2020-02-22 02:00:55 +00:00
|
|
|
foreach(var entry in app.plugin_registry.conversation_titlebar_entries) {
|
|
|
|
titlebar.insert_entry(entry);
|
|
|
|
}
|
2020-02-21 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void select_conversation(Conversation? conversation, bool default_initialize_conversation) {
|
|
|
|
this.conversation = conversation;
|
|
|
|
|
|
|
|
chat_input_controller.set_conversation(conversation);
|
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
update_conversation_display_name();
|
|
|
|
update_conversation_topic();
|
|
|
|
|
|
|
|
foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) {
|
|
|
|
Plugins.ConversationTitlebarWidget view = e.get_widget(Plugins.WidgetType.GTK);
|
|
|
|
if (view != null) {
|
|
|
|
view.set_conversation(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:11:23 +00:00
|
|
|
if (default_initialize_conversation) {
|
2020-02-21 01:42:19 +00:00
|
|
|
view.conversation_frame.initialize_for_conversation(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unset_conversation() {
|
|
|
|
conversation_display_name = null;
|
|
|
|
conversation_topic = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void update_conversation_display_name() {
|
|
|
|
conversation_display_name = Util.get_conversation_display_name(stream_interactor, conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void update_conversation_topic(string? subtitle = null) {
|
|
|
|
if (subtitle != null) {
|
|
|
|
conversation_topic = Util.summarize_whitespaces_to_space(subtitle);
|
|
|
|
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
|
|
|
|
string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
|
|
|
|
if (subject != null) {
|
|
|
|
conversation_topic = Util.summarize_whitespaces_to_space(subject);
|
|
|
|
} else {
|
|
|
|
conversation_topic = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
conversation_topic = null;
|
2020-02-21 01:11:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
private void on_drag_data_received(Widget widget, Gdk.DragContext context, int x, int y, SelectionData selection_data, uint target_type, uint time) {
|
2020-02-21 01:11:23 +00:00
|
|
|
if ((selection_data != null) && (selection_data.get_length() >= 0)) {
|
|
|
|
switch (target_type) {
|
|
|
|
case Target.URI_LIST:
|
|
|
|
string[] uris = selection_data.get_uris();
|
|
|
|
for (int i = 0; i < uris.length; i++) {
|
|
|
|
try {
|
|
|
|
string filename = Filename.from_uri(uris[i]);
|
|
|
|
stream_interactor.get_module(FileManager.IDENTITY).send_file.begin(filename, conversation);
|
|
|
|
} catch (Error err) {}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:42:19 +00:00
|
|
|
private bool forward_key_press_to_chat_input(EventKey event) {
|
2020-02-21 01:11:23 +00:00
|
|
|
// Don't forward / change focus on Control / Alt
|
|
|
|
if (event.keyval == Gdk.Key.Control_L || event.keyval == Gdk.Key.Control_R ||
|
|
|
|
event.keyval == Gdk.Key.Alt_L || event.keyval == Gdk.Key.Alt_R) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Don't forward / change focus on Control + ...
|
|
|
|
if ((event.state & ModifierType.CONTROL_MASK) > 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-21 01:42:19 +00:00
|
|
|
view.chat_input.text_input.key_press_event(event);
|
|
|
|
view.chat_input.text_input.grab_focus();
|
2020-02-21 01:11:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|