aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/chat_input
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2018-04-24 14:59:28 +0200
committerfiaxh <git@mx.ax.lt>2018-04-30 11:03:59 +0200
commitc1533f25775d3d9db5395107d6f3fd695b041926 (patch)
tree340a3da2c48cb9809a00b734c35c8172e9b89b6c /main/src/ui/chat_input
parentf0dd0e0c3af10f2772efd94aadbded38f3c155bb (diff)
downloaddino-c1533f25775d3d9db5395107d6f3fd695b041926.tar.gz
dino-c1533f25775d3d9db5395107d6f3fd695b041926.zip
Redesign chat input + move file upload there
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r--main/src/ui/chat_input/view.vala70
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;
+ }
+ }
}
}