aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_view_controller.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-04-22 15:44:12 +0200
committerfiaxh <git@lightrise.org>2020-04-22 15:44:12 +0200
commit51a23728694a3f1312cc9396fc093ca178457c3c (patch)
tree321771ae3d807d19387a8656805a648d75347994 /main/src/ui/conversation_view_controller.vala
parent7c4260eed718961874fc0ea665263ea2ce59338b (diff)
downloaddino-51a23728694a3f1312cc9396fc093ca178457c3c.tar.gz
dino-51a23728694a3f1312cc9396fc093ca178457c3c.zip
Add file upload preview
fixes #756
Diffstat (limited to 'main/src/ui/conversation_view_controller.vala')
-rw-r--r--main/src/ui/conversation_view_controller.vala69
1 files changed, 65 insertions, 4 deletions
diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala
index dce9920e..8e17cc91 100644
--- a/main/src/ui/conversation_view_controller.vala
+++ b/main/src/ui/conversation_view_controller.vala
@@ -22,6 +22,7 @@ public class ConversationViewController : Object {
private Application app;
private ConversationView view;
+ private Widget? overlay_dialog;
private ConversationTitlebar titlebar;
public SearchMenuEntry search_menu_entry = new SearchMenuEntry();
@@ -36,15 +37,15 @@ public class ConversationViewController : Object {
this.app = GLib.Application.get_default() as Application;
this.chat_input_controller = new ChatInputController(view.chat_input, stream_interactor);
+ chat_input_controller.activate_last_message_correction.connect(() => view.conversation_frame.activate_last_message_correction());
+ chat_input_controller.file_picker_selected.connect(() => on_file_picker_selected());
view.conversation_frame.init(stream_interactor);
// drag 'n drop file upload
- Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY);
view.drag_data_received.connect(this.on_drag_data_received);
// forward key presses
- chat_input_controller.activate_last_message_correction.connect(() => view.conversation_frame.activate_last_message_correction());
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);
@@ -79,6 +80,8 @@ public class ConversationViewController : Object {
}
});
+ stream_interactor.get_module(FileManager.IDENTITY).upload_available.connect(update_file_upload_status);
+
// Headerbar plugins
app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor));
app.plugin_registry.register_contact_titlebar_entry(search_menu_entry);
@@ -89,8 +92,17 @@ public class ConversationViewController : Object {
}
public void select_conversation(Conversation? conversation, bool default_initialize_conversation) {
+ if (this.conversation != null) {
+ conversation.notify["encryption"].disconnect(update_file_upload_status);
+ }
+ if (overlay_dialog != null) {
+ overlay_dialog.destroy();
+ }
+
this.conversation = conversation;
+ conversation.notify["encryption"].connect(update_file_upload_status);
+
chat_input_controller.set_conversation(conversation);
update_conversation_display_name();
@@ -106,6 +118,8 @@ public class ConversationViewController : Object {
if (default_initialize_conversation) {
view.conversation_frame.initialize_for_conversation(conversation);
}
+
+ update_file_upload_status();
}
public void unset_conversation() {
@@ -113,6 +127,16 @@ public class ConversationViewController : Object {
conversation_topic = null;
}
+ private void update_file_upload_status() {
+ bool upload_available = stream_interactor.get_module(FileManager.IDENTITY).is_upload_available(conversation);
+ chat_input_controller.set_file_upload_active(upload_available);
+ if (upload_available) {
+ Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY);
+ } else {
+ Gtk.drag_dest_unset(view);
+ }
+ }
+
private void update_conversation_display_name() {
conversation_display_name = Util.get_conversation_display_name(stream_interactor, conversation);
}
@@ -139,8 +163,8 @@ public class ConversationViewController : Object {
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);
+ string file_path = Filename.from_uri(uris[i]);
+ open_send_file_overlay(File.new_for_path(file_path));
} catch (Error err) {}
}
break;
@@ -150,6 +174,43 @@ public class ConversationViewController : Object {
}
}
+ private void on_file_picker_selected() {
+ PreviewFileChooserNative chooser = new PreviewFileChooserNative(_("Select file"), view.get_toplevel() as Gtk.Window, FileChooserAction.OPEN, _("Select"), _("Cancel"));
+ if (chooser.run() == Gtk.ResponseType.ACCEPT) {
+ open_send_file_overlay(File.new_for_path(chooser.get_filename()));
+ }
+ }
+
+ private void open_send_file_overlay(File file) {
+ FileInfo file_info;
+ try {
+ file_info = file.query_info("*", FileQueryInfoFlags.NONE);
+ } catch (Error e) { return; }
+
+ FileSendOverlay overlay = new FileSendOverlay(file, file_info);
+ overlay.send_file.connect(() => send_file(file));
+
+ HashMap<int, long> limits = stream_interactor.get_module(FileManager.IDENTITY).get_file_size_limits(conversation);
+ bool something_works = false;
+ foreach (var limit in limits.values) {
+ if (limit >= file_info.get_size()) {
+ something_works = true;
+ }
+ }
+ if (!something_works && limits.has_key(0)) {
+ if (!something_works && file_info.get_size() > limits[0]) {
+ overlay.set_file_too_large();
+ }
+ }
+
+ view.add_overlay_dialog(overlay);
+ overlay_dialog = overlay;
+ }
+
+ private void send_file(File file) {
+ stream_interactor.get_module(FileManager.IDENTITY).send_file.begin(file, conversation);
+ }
+
private bool forward_key_press_to_chat_input(EventKey event) {
if (((Gtk.Window)view.get_toplevel()).get_focus() is TextView) {
return false;