diff options
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r-- | main/src/ui/chat_input/view.vala | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala index c9db730a..93f32fb7 100644 --- a/main/src/ui/chat_input/view.vala +++ b/main/src/ui/chat_input/view.vala @@ -7,12 +7,11 @@ using Xmpp; namespace Dino.Ui.ChatInput { -[GtkTemplate (ui = "/im/dino/Dino/chat_input.ui")] public class View : Box { - [GtkChild] private ScrolledWindow scrolled; - [GtkChild] private TextView text_input; - [GtkChild] private Box box; + private ScrolledWindow scrolled; + private TextView text_input; + private Box outer_box; public string text { owned get { return text_input.buffer.text; } @@ -26,20 +25,62 @@ public class View : Box { private OccupantsTabCompletor occupants_tab_completor; private SmileyConverter smiley_converter; private EditHistory edit_history; - private EncryptionButton encryption_widget = new EncryptionButton() { yalign=0, visible=true }; + private EncryptionButton encryption_widget; + private Button file_button = new Button.from_icon_name("mail-attachment-symbolic", IconSize.MENU) { margin_top=3, valign=Align.START, relief=ReliefStyle.NONE }; + private Separator file_separator = new Separator(Orientation.VERTICAL); public View(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - occupants_tab_completor = new OccupantsTabCompletor(stream_interactor, text_input); - smiley_converter = new SmileyConverter(stream_interactor, text_input); - edit_history = new EditHistory(text_input, GLib.Application.get_default()); - box.add(encryption_widget); + outer_box = new Box(Orientation.HORIZONTAL, 0) { visible=true }; + + file_button.get_style_context().add_class("dino-chatinput-button"); + file_button.clicked.connect(() => { + PreviewFileChooserNative chooser = new PreviewFileChooserNative("Select file", get_toplevel() as Gtk.Window, FileChooserAction.OPEN, "Select", "Cancel"); + + // long max_file_size = stream_interactor.get_module(Manager.IDENTITY).get_max_file_size(conversation.account); + // if (max_file_size != -1) { + // FileFilter filter = new FileFilter(); + // filter.add_custom(FileFilterFlags.URI, (filter_info) => { + // File file = File.new_for_uri(filter_info.uri); + // FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); + // return file_info.get_size() <= max_file_size; + // }); + // chooser.set_filter(filter); + // } + if (chooser.run() == Gtk.ResponseType.ACCEPT) { + string uri = chooser.get_filename(); + stream_interactor.get_module(FileManager.IDENTITY).send_file(uri, conversation); + } + }); + outer_box.add(file_button); + outer_box.add(file_separator); + + scrolled = new ScrolledWindow(null, null) { max_content_height=300, propagate_natural_height=true, visible=true }; + text_input = new TextView() { valign=Align.CENTER, wrap_mode=WrapMode.WORD_CHAR, margin=8, can_focus=true, hexpand=true, visible=true }; + + scrolled.add(text_input); + outer_box.add(scrolled); + + encryption_widget = new EncryptionButton() { margin_top=3, valign=Align.START, visible=true }; encryption_widget.get_style_context().add_class("dino-chatinput-button"); + outer_box.add(encryption_widget); + scrolled.get_vscrollbar().get_preferred_height(out vscrollbar_min_height, null); scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify); text_input.key_press_event.connect(on_text_input_key_press); text_input.buffer.changed.connect(on_text_input_changed); + + Frame frame = new Frame(null) { margin=12, margin_top=0, visible=true }; + Util.force_css(frame, "* { border-radius: 3px; }"); + frame.add(outer_box); + this.add(frame); + + occupants_tab_completor = new OccupantsTabCompletor(stream_interactor, text_input); + smiley_converter = new SmileyConverter(stream_interactor, text_input); + edit_history = new EditHistory(text_input, GLib.Application.get_default()); + + stream_interactor.get_module(FileManager.IDENTITY).upload_available.connect(on_upload_available); } public void initialize_for_conversation(Conversation conversation) { @@ -50,6 +91,10 @@ public class View : Box { if (this.conversation != null) entry_cache[this.conversation] = text_input.buffer.text; this.conversation = conversation; + bool upload_available = stream_interactor.get_module(FileManager.IDENTITY).is_upload_available(conversation); + file_button.visible = upload_available; + file_separator.visible = upload_available; + text_input.buffer.changed.disconnect(on_text_input_changed); text_input.buffer.text = ""; if (entry_cache.has_key(conversation)) { @@ -135,6 +180,13 @@ public class View : Box { stream_interactor.get_module(ChatInteraction.IDENTITY).on_message_cleared(conversation); } } + + private void on_upload_available(Account account) { + if (conversation != null && conversation.account.equals(account)) { + file_button.visible = true; + file_separator.visible = true; + } + } } } |