Add image sending via clipboard paste

fixes #385
This commit is contained in:
fiaxh 2020-06-04 14:03:34 +02:00
parent 8a64c8501d
commit cdc505f550
2 changed files with 16 additions and 0 deletions

View file

@ -11,6 +11,7 @@ public class ChatInputController : Object {
public signal void activate_last_message_correction(); public signal void activate_last_message_correction();
public signal void file_picker_selected(); public signal void file_picker_selected();
public signal void clipboard_pasted();
public new string? conversation_display_name { get; set; } public new string? conversation_display_name { get; set; }
public string? conversation_topic { get; set; } public string? conversation_topic { get; set; }
@ -35,6 +36,7 @@ public class ChatInputController : Object {
chat_input.chat_text_view.text_view.buffer.changed.connect(on_text_input_changed); chat_input.chat_text_view.text_view.buffer.changed.connect(on_text_input_changed);
chat_input.chat_text_view.text_view.key_press_event.connect(on_text_input_key_press); chat_input.chat_text_view.text_view.key_press_event.connect(on_text_input_key_press);
chat_input.chat_text_view.text_view.paste_clipboard.connect(() => clipboard_pasted());
chat_text_view_controller.send_text.connect(send_text); chat_text_view_controller.send_text.connect(send_text);

View file

@ -39,6 +39,7 @@ public class ConversationViewController : Object {
this.chat_input_controller = new ChatInputController(view.chat_input, stream_interactor); 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.activate_last_message_correction.connect(() => view.conversation_frame.activate_last_message_correction());
chat_input_controller.file_picker_selected.connect(() => open_file_picker()); chat_input_controller.file_picker_selected.connect(() => open_file_picker());
chat_input_controller.clipboard_pasted.connect(on_clipboard_paste);
view.conversation_frame.init(stream_interactor); view.conversation_frame.init(stream_interactor);
@ -165,6 +166,19 @@ public class ConversationViewController : Object {
} }
} }
private void on_clipboard_paste() {
Clipboard clipboard = Clipboard.get(Gdk.SELECTION_CLIPBOARD);
if (clipboard.wait_is_image_available()) {
clipboard.request_image((_, pixbuf) => {
File file = File.new_for_path(Path.build_filename(FileManager.get_storage_dir(), Xmpp.random_uuid() + ".png"));
DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION));
pixbuf.save_to_stream_async.begin(fos, "png", null, () => {
open_send_file_overlay(file);
});
});
}
}
private void on_drag_data_received(Widget widget, Gdk.DragContext context, int x, int y, SelectionData selection_data, uint target_type, uint time) { private void on_drag_data_received(Widget widget, Gdk.DragContext context, int x, int y, SelectionData selection_data, uint target_type, uint time) {
if ((selection_data != null) && (selection_data.get_length() >= 0)) { if ((selection_data != null) && (selection_data.get_length() >= 0)) {
switch (target_type) { switch (target_type) {