diff options
author | fiaxh <git@mx.ax.lt> | 2017-10-14 19:34:30 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-10-21 23:31:05 +0200 |
commit | 8b43df8ec3f92477f857280668a9f29f0b9d6229 (patch) | |
tree | bb7d1411e0c3f486d3977e2edad2b701702c2362 /main/src | |
parent | 9d8e1e88ec61403659a8cc410d5c4414e3bd3a96 (diff) | |
download | dino-8b43df8ec3f92477f857280668a9f29f0b9d6229.tar.gz dino-8b43df8ec3f92477f857280668a9f29f0b9d6229.zip |
Handle file uploading in libdino & main, have http upload as provider
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/ui/chat_input/smiley_converter.vala | 4 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/file_entry.vala | 72 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/view.vala | 1 |
3 files changed, 75 insertions, 2 deletions
diff --git a/main/src/ui/chat_input/smiley_converter.vala b/main/src/ui/chat_input/smiley_converter.vala index f8d29225..6844222e 100644 --- a/main/src/ui/chat_input/smiley_converter.vala +++ b/main/src/ui/chat_input/smiley_converter.vala @@ -13,7 +13,7 @@ class SmileyConverter { private static HashMap<string, string> smiley_translations = new HashMap<string, string>(); static construct { - smiley_translations[":)"] = "☺"; + smiley_translations[":)"] = "🙂"; smiley_translations[":D"] = "😀"; smiley_translations[";)"] = "😉"; smiley_translations["O:)"] = "😇"; @@ -22,7 +22,7 @@ class SmileyConverter { smiley_translations[":o"] = "😮"; smiley_translations[":P"] = "😛"; smiley_translations[";P"] = "😜"; - smiley_translations[":("] = "☹"; + smiley_translations[":("] = "🙁"; smiley_translations[":'("] = "😢"; smiley_translations[":/"] = "😕"; } diff --git a/main/src/ui/conversation_titlebar/file_entry.vala b/main/src/ui/conversation_titlebar/file_entry.vala new file mode 100644 index 00000000..df173192 --- /dev/null +++ b/main/src/ui/conversation_titlebar/file_entry.vala @@ -0,0 +1,72 @@ +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +public class FileEntry : Plugins.ConversationTitlebarEntry, Object { + public string id { get { return "send_files"; } } + + StreamInteractor stream_interactor; + + public FileEntry(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + } + + public double order { get { return 4; } } + public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { + if (type == Plugins.WidgetType.GTK) { + return new FileWidget(stream_interactor) { visible=true }; + } + return null; + } +} + +public class FileWidget : Button, Plugins.ConversationTitlebarWidget { + + private Conversation? conversation; + private StreamInteractor stream_interactor; + + public FileWidget(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + image = new Image.from_icon_name("mail-attachment-symbolic", IconSize.MENU); + clicked.connect(on_clicked); + stream_interactor.get_module(FileManager.IDENTITY).upload_available.connect(on_upload_available); + } + + public void on_clicked() { + FileChooserNative chooser = new FileChooserNative ( + "Select file", get_toplevel() as 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); + } + } + + public void on_upload_available(Account account) { + Idle.add(() => { + if (conversation != null && conversation.account.equals(account)) { + visible = true; + } + return false; + }); + } + + public new void set_conversation(Conversation conversation) { + this.conversation = conversation; + visible = stream_interactor.get_module(FileManager.IDENTITY).is_upload_available(conversation); + } +} + +} diff --git a/main/src/ui/conversation_titlebar/view.vala b/main/src/ui/conversation_titlebar/view.vala index 32d829fb..bd8fe8c9 100644 --- a/main/src/ui/conversation_titlebar/view.vala +++ b/main/src/ui/conversation_titlebar/view.vala @@ -23,6 +23,7 @@ public class ConversationTitlebar : Gtk.HeaderBar { Application app = GLib.Application.get_default() as Application; app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor)); app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor, window)); + app.plugin_registry.register_contact_titlebar_entry(new FileEntry(stream_interactor)); foreach(var e in app.plugin_registry.conversation_titlebar_entries) { Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK); |