diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-06 00:39:55 +0100 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-06 00:39:55 +0100 |
commit | ba4fbab831b09bd66fca8136333db384b44ff6c1 (patch) | |
tree | db385c694fba440063562354741a79cbc9ea5ef7 /src/chat.py | |
parent | d68dbc893c4b76627b28b189b870aedddcad55bb (diff) |
chat: Add support for file upload
Diffstat (limited to 'src/chat.py')
-rw-r--r-- | src/chat.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/chat.py b/src/chat.py index 5e52347..bb498c3 100644 --- a/src/chat.py +++ b/src/chat.py @@ -24,6 +24,7 @@ from gi.repository import GObject from .message import WeegtkMessage from .color import Color from weegtk import config +from weegtk import netfile import json @@ -153,3 +154,20 @@ class WeegtkChat(Adw.Bin): entry_buffer.set_text("", 0) self.emit("buffer_input", self.data['full_name'], text) + def open_file_dialog(self, dialog, result, caller): + try: + file = dialog.open_finish(result) + except GLib.GError: + # gtk-dialog-error-quark: Dismissed by user + pass + else: + conf = config.read() + file_url = netfile.upload(file.get_path(), conf["upload"]["url"]) + entry_buffer = self.text_entry.get_buffer() + entry_buffer.insert_text(self.text_entry.get_position(), file_url, -1) + + @Gtk.Template.Callback() + def attach_file(self, *args): + dialog = Gtk.FileDialog() + dialog.set_title("Select file to upload") + dialog.open(self.get_root(), None, self.open_file_dialog, self) |