From ba4fbab831b09bd66fca8136333db384b44ff6c1 Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Sun, 6 Oct 2024 00:39:55 +0100 Subject: chat: Add support for file upload --- src/chat.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/chat.py') 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) -- cgit