diff options
author | lovetox <philipp@hoerist.com> | 2021-02-18 00:05:16 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2021-02-27 14:54:10 +0300 |
commit | 99ffe9b13a6be1b48ee4dfce63405bad190e7811 (patch) | |
tree | 8e0619d41a25e0413c7bdd2281e11574205f5384 | |
parent | 039e3eb13ae14dd82afd550749eaca017e11b5d2 (diff) |
Profile: Show error if avatar upload fails
-rw-r--r-- | gajim/gtk/profile.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gajim/gtk/profile.py b/gajim/gtk/profile.py index 199bcca0f..c98fccb3b 100644 --- a/gajim/gtk/profile.py +++ b/gajim/gtk/profile.py @@ -236,8 +236,10 @@ class ProfileWindow(Gtk.ApplicationWindow): else: # Only update avatar if it changed - con.get_module('UserAvatar').set_avatar(self._new_avatar, - public=public) + con.get_module('UserAvatar').set_avatar( + self._new_avatar, + public=public, + callback=self._on_set_avatar) nick = GLib.markup_escape_text(self._ui.nickname_entry.get_text()) con.get_module('UserNickname').set_nickname(nick, public=public) @@ -247,6 +249,28 @@ class ProfileWindow(Gtk.ApplicationWindow): self.account, 'name') app.nicks[self.account] = nick + def _on_set_avatar(self, task): + try: + task.finish() + except StanzaError as error: + if self._new_avatar is None: + # Trying to remove the avatar but the node does not exist + if error.condition == 'item-not-found': + return + + title = _('Error while uploading avatar') + text = error.get_text() + + if (error.condition == 'not-acceptable' and + error.app_condition == 'payload-too-big'): + text = _('Avatar file size too big') + + ErrorDialog(title, text) + + self._ui.avatar_image.set_from_surface(self._current_avatar) + self._new_avatar = False + return + def _on_remove_avatar(self, _button): contact = app.contacts.create_contact(self._jid, self.account) scale = self.get_scale_factor() |