Now About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 00:39:55 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 00:39:55 +0100
commitba4fbab831b09bd66fca8136333db384b44ff6c1 (patch)
treedb385c694fba440063562354741a79cbc9ea5ef7
parentd68dbc893c4b76627b28b189b870aedddcad55bb (diff)
chat: Add support for file upload
-rw-r--r--com.fryzekconcepts.weegtk.json70
-rw-r--r--src/chat.py18
-rw-r--r--src/config.py3
-rw-r--r--src/gtk/chat.ui18
-rw-r--r--src/gtk/preferences.ui11
-rw-r--r--src/meson.build3
-rw-r--r--src/message.py2
-rw-r--r--src/preferences.py6
-rw-r--r--src/relay/netfile.py25
9 files changed, 153 insertions, 3 deletions
diff --git a/com.fryzekconcepts.weegtk.json b/com.fryzekconcepts.weegtk.json
index f057400..63253f2 100644
--- a/com.fryzekconcepts.weegtk.json
+++ b/com.fryzekconcepts.weegtk.json
@@ -24,6 +24,76 @@
],
"modules" : [
{
+ "name" : "python3-urllib3",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "pip install --prefix=/app urllib3-2.2.3-py3-none-any.whl"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "url" : "https://files.pythonhosted.org/packages/ce/d9/5f4c13cecde62396b0d3fe530a50ccea91e7dfc1ccf0e09c228841bb5ba8/urllib3-2.2.3-py3-none-any.whl",
+ "sha256" : "ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac"
+ }
+ ]
+ },
+ {
+ "name" : "python3-idna",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "pip install --prefix=/app idna-3.10-py3-none-any.whl"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "url" : "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl",
+ "sha256" : "946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"
+ }
+ ]
+ },
+ {
+ "name" : "python3-charsetnormalizer",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "pip install --prefix=/app charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "url" : "https://files.pythonhosted.org/packages/ee/fb/14d30eb4956408ee3ae09ad34299131fb383c47df355ddb428a7331cfa1e/charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
+ "sha256" : "90d558489962fd4918143277a773316e56c72da56ec7aa3dc3dbbe20fdfed15b"
+ }
+ ]
+ },
+ {
+ "name" : "python3-certifi",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "pip install --prefix=/app certifi-2024.8.30-py3-none-any.whl"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "url" : "https://files.pythonhosted.org/packages/12/90/3c9ff0512038035f59d279fddeb79f5f1eccd8859f06d6163c58798b9487/certifi-2024.8.30-py3-none-any.whl",
+ "sha256" : "922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"
+ }
+ ]
+ },
+ {
+ "name" : "python3-requests",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "pip install --prefix=/app requests-2.32.3-py3-none-any.whl"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "url" : "https://files.pythonhosted.org/packages/f9/9b/335f9764261e915ed497fcdeb11df5dfd6f7bf257d4a6a2a686d80da4d54/requests-2.32.3-py3-none-any.whl",
+ "sha256" : "70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"
+ }
+ ]
+ },
+ {
"name" : "python3-pycparser",
"buildsystem" : "simple",
"build-commands" : [
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)
diff --git a/src/config.py b/src/config.py
index ee9d611..ac52063 100644
--- a/src/config.py
+++ b/src/config.py
@@ -32,7 +32,7 @@ CONFIG_FILENAME = f"{CONFIG_DIR}/weegtk.conf"
CONFIG_DEFAULT_RELAY_LINES = 50
-CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color', 'ssh')
+CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color', 'ssh', 'upload')
CONFIG_DEFAULT_OPTIONS = (('relay.hostname', ''),
('relay.port', ''),
('relay.ssl', 'off'),
@@ -43,6 +43,7 @@ CONFIG_DEFAULT_OPTIONS = (('relay.hostname', ''),
('ssh.port', ''),
('ssh.username', ''),
('ssh.key', ''),
+ ('upload.url', ''),
('look.debug', 'off'),
('look.statusbar', 'off'))
diff --git a/src/gtk/chat.ui b/src/gtk/chat.ui
index 233c362..6959d45 100644
--- a/src/gtk/chat.ui
+++ b/src/gtk/chat.ui
@@ -52,6 +52,15 @@
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<child>
+ <object class="GtkButton">
+ <property name="icon-name">mail-attachment</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <signal name="clicked" handler="attach_file"/>
+ </object>
+ </child>
+ <child>
<object class="GtkEntry" id="text_entry">
<property name="halign">fill</property>
<property name="hexpand">True</property>
@@ -62,6 +71,15 @@
<signal name="activate" handler="entry_activate"/>
</object>
</child>
+ <child>
+ <object class="GtkButton">
+ <property name="icon-name">mail-forward</property>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <signal name="clicked" handler="entry_activate"/>
+ </object>
+ </child>
</object>
</property>
</object>
diff --git a/src/gtk/preferences.ui b/src/gtk/preferences.ui
index 5823d2f..9e4d9fc 100644
--- a/src/gtk/preferences.ui
+++ b/src/gtk/preferences.ui
@@ -77,6 +77,17 @@
</child>
</object>
</child>
+ <child>
+ <object class="AdwPreferencesGroup">
+ <property name="title" translatable="yes">Upload</property>
+ <child>
+ <object class="AdwEntryRow" id="upload_url">
+ <property name="title" translatable="yes">Upload URL</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</template>
diff --git a/src/meson.build b/src/meson.build
index 3225adc..649a19e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -36,7 +36,8 @@ weegtk_sources = [
'preferences.py',
'relay/network.py',
'relay/protocol.py',
- 'relay/color.py'
+ 'relay/color.py',
+ 'relay/netfile.py'
]
install_data(weegtk_sources, install_dir: moduledir)
diff --git a/src/message.py b/src/message.py
index 4e37609..27cf817 100644
--- a/src/message.py
+++ b/src/message.py
@@ -1,4 +1,4 @@
-# window.py
+# message.py
#
# Copyright 2024 Lucas Fryzek
#
diff --git a/src/preferences.py b/src/preferences.py
index d864012..1a87e29 100644
--- a/src/preferences.py
+++ b/src/preferences.py
@@ -39,6 +39,8 @@ class WeegtkPreferences(Adw.PreferencesDialog):
ssh_key_path = ""
+ upload_url = Gtk.Template.Child()
+
def __init__(self, **kwargs):
super().__init__(**kwargs)
@@ -53,6 +55,8 @@ class WeegtkPreferences(Adw.PreferencesDialog):
self.ssh_username.set_text(self.config["ssh"]["username"])
self.set_ssh_key(self.config["ssh"]["key"])
+ self.upload_url.set_text(self.config["upload"]["url"])
+
self.install_action("ssh_key.open", None, self.ssh_key_open)
def read_preferences(self):
@@ -65,6 +69,8 @@ class WeegtkPreferences(Adw.PreferencesDialog):
self.config["ssh"]["username"] = self.ssh_username.get_text()
self.config["ssh"]["key"] = self.ssh_key_path
+ self.config["upload"]["url"] = self.upload_url.get_text()
+
def set_ssh_key(self, key_path):
self.ssh_key_path = key_path
short_name = os.path.basename(key_path)
diff --git a/src/relay/netfile.py b/src/relay/netfile.py
new file mode 100644
index 0000000..321b810
--- /dev/null
+++ b/src/relay/netfile.py
@@ -0,0 +1,25 @@
+# netfile.py
+#
+# Copyright 2024 Lucas Fryzek
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+import requests
+
+def upload(filepath, upload_url):
+ files = {'file': open(filepath, 'rb')}
+
+ r = requests.post(upload_url, files=files)
+ return r.text.strip()