Commit 4fa36ef2 authored by Philipp Hörist's avatar Philipp Hörist

Handle multi language error results

parent 40b0b524
Pipeline #3993 passed with stages
in 2 minutes and 30 seconds
......@@ -70,6 +70,7 @@ from gajim.common import configpaths
from gajim.common.i18n import Q_
from gajim.common.i18n import _
from gajim.common.i18n import ngettext
from gajim.common.i18n import get_rfc5646_lang
from gajim.common.const import ShowConstant
from gajim.common.const import Display
from gajim.common.const import URIType
......@@ -1613,3 +1614,14 @@ def validate_jid(jid):
return JID(str(jid))
except InvalidJid as error:
raise ValueError(error)
def to_user_string(error):
text = error.get_text(get_rfc5646_lang())
if text:
return text
condition = error.condition
if error.app_condition is not None:
return '%s (%s)' % (condition, error.app_condition)
return condition
......@@ -64,7 +64,7 @@ class Blocking(BaseModule):
def _blocking_list_received(self, result):
if is_error_result(result):
self._log.info('Error: %s', result)
self._log.info(result)
return
self.blocked = result.blocking_list
......
......@@ -161,7 +161,7 @@ class Bookmarks(BaseModule):
def _bookmarks_received(self, bookmarks):
if is_error_result(bookmarks):
self._log.info('Error: %s', bookmarks)
self._log.info(bookmarks)
bookmarks = []
self._request_in_progress = False
......
......@@ -212,7 +212,7 @@ class Discovery(BaseModule):
def _muc_info_response(self, result, callback):
if is_error_result(result):
if result.type == 'item-not-found':
if result.condition == 'item-not-found':
# Groupchat does not exist
self._log.info('MUC does not exist: %s', result.jid)
callback()
......
......@@ -22,6 +22,7 @@ from nbxmpp.structs import StanzaHandler
from nbxmpp.util import is_error_result
from gajim.common import app
from gajim.common.helpers import to_user_string
from gajim.common.modules.base import BaseModule
from gajim.common.file_props import FilesProp
......@@ -149,8 +150,8 @@ class IBB(BaseModule):
def _on_open_result(self, result, file_props):
if is_error_result(result):
app.socks5queue.error_cb('Error', str(result))
self._log.warning('Error: %s', result)
app.socks5queue.error_cb('Error', to_user_string(result))
self._log.warning(result)
return
self.send_data(file_props)
......@@ -183,8 +184,8 @@ class IBB(BaseModule):
def _on_close_result(self, result):
if is_error_result(result):
app.socks5queue.error_cb('Error', str(result))
self._log.warning('Error: %s', result)
app.socks5queue.error_cb('Error', to_user_string(result))
self._log.warning(result)
return
def send_data(self, file_props):
......@@ -217,8 +218,8 @@ class IBB(BaseModule):
def _on_data_result(self, result, file_props):
if is_error_result(result):
app.socks5queue.error_cb('Error', str(result))
self._log.warning('Error: %s', result)
app.socks5queue.error_cb('Error', to_user_string(result))
self._log.warning(result)
return
self.send_data(file_props)
......
......@@ -38,6 +38,7 @@ from gajim.common.const import SyncThreshold
from gajim.common.helpers import AdditionalDataDict
from gajim.common.helpers import get_default_muc_config
from gajim.common.helpers import get_sync_threshold
from gajim.common.helpers import to_user_string
from gajim.common import idle
from gajim.common.caps_cache import muc_caps_cache
from gajim.common.nec import NetworkEvent
......@@ -181,7 +182,7 @@ class MUC(BaseModule):
def _on_room_config(self, result):
if is_error_result(result):
self._log.info('Error: %s', result)
self._log.info(result)
app.nec.push_incoming_event(NetworkEvent(
'muc-configuration-failed',
account=self._account,
......@@ -212,7 +213,7 @@ class MUC(BaseModule):
def _on_config_result(self, result):
if is_error_result(result):
self._log.info('Error: %s', result)
self._log.info(result)
app.nec.push_incoming_event(NetworkEvent(
'muc-configuration-failed',
account=self._account,
......@@ -657,7 +658,7 @@ class MUC(BaseModule):
NetworkEvent('muc-captcha-error',
account=self._account,
room_jid=str(result.jid),
error_text=result.message))
error_text=to_user_string(result)))
def _on_config_change(self, _con, _stanza, properties):
if not properties.is_muc_config_change:
......
......@@ -63,7 +63,7 @@ class UserAvatar(BaseModule):
def _avatar_received(self, result):
if is_error_result(result):
self._log.info('Error: %s', result)
self._log.info(result)
return
self._log.info('Received Avatar: %s %s', result.jid, result.sha)
......
......@@ -671,7 +671,7 @@ class GroupchatControl(ChatControlBase):
def _on_configure_form_received(self, result):
if is_error_result(result):
log.info('Error %s %s', result.jid, result)
log.info(result)
return
GroupchatConfig(self.account, result.jid, 'owner', result.form)
......
......@@ -23,6 +23,7 @@ from nbxmpp.modules import dataforms
from gajim.common import app
from gajim.common.i18n import _
from gajim.common.helpers import to_user_string
from gajim.gtk.dataform import DataFormWidget
from gajim.gtk.util import ensure_not_destroyed
......@@ -189,7 +190,7 @@ class AdHocCommand(Gtk.Assistant):
def _received_command_list(self, commands):
error_text = None
if is_error_result(commands):
error_text = str(commands)
error_text = to_user_string(commands)
elif not commands:
error_text = _('No commands available')
......@@ -206,7 +207,7 @@ class AdHocCommand(Gtk.Assistant):
@ensure_not_destroyed
def _received_stage(self, stage):
if is_error_result(stage):
self.get_nth_page(Page.ERROR).set_text(str(stage))
self.get_nth_page(Page.ERROR).set_text(to_user_string(stage))
self.get_nth_page(Page.ERROR).show_command_button = True
self.set_current_page(Page.ERROR)
return
......
......@@ -21,6 +21,7 @@ from gi.repository import GLib
from gajim.common import app
from gajim.common.i18n import _
from gajim.common.helpers import to_user_string
from gajim.gtk.util import get_builder
from gajim.gtk.dialogs import HigDialog
......@@ -69,7 +70,7 @@ class BlockingList(Gtk.ApplicationWindow):
dialog = HigDialog(
self, Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
_('Error!'),
GLib.markup_escape_text(str(error)))
GLib.markup_escape_text(error))
dialog.popup()
def _on_blocking_list_received(self, result):
......@@ -78,7 +79,7 @@ class BlockingList(Gtk.ApplicationWindow):
self._set_grid_state(not is_error)
if is_error:
self._show_error(result)
self._show_error(to_user_string(result))
else:
self._prev_blocked_jids = set(result.blocking_list)
......@@ -89,7 +90,7 @@ class BlockingList(Gtk.ApplicationWindow):
def _on_save_result(self, result):
self._await_results -= 1
if is_error_result(result) and not self._received_errors:
self._show_error(result)
self._show_error(to_user_string(result))
self._received_errors = True
if not self._await_results:
......
......@@ -357,7 +357,7 @@ class GroupchatConfig(Gtk.ApplicationWindow):
def _on_affiliations_received(self, result, affiliation):
if is_error_result(result):
log.info('Error while requesting %s affiliations: %s',
affiliation, result)
affiliation, result.condition)
return
if affiliation == 'outcast':
......
......@@ -25,6 +25,7 @@ from gajim.common.const import MUC_CREATION_EXAMPLES
from gajim.common.const import MUC_DISCO_ERRORS
from gajim.common.i18n import _
from gajim.common.helpers import validate_jid
from gajim.common.helpers import to_user_string
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.util import get_builder
......@@ -158,7 +159,7 @@ class CreateGroupchatWindow(Gtk.ApplicationWindow):
self._ui.create_button.set_sensitive(False)
def _set_warning_from_error(self, error):
text = MUC_DISCO_ERRORS.get(error.type, str(error))
text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error))
self._set_warning(text)
def _set_warning_from_error_code(self, error_code):
......@@ -192,7 +193,7 @@ class CreateGroupchatWindow(Gtk.ApplicationWindow):
@ensure_not_destroyed
def _disco_info_received(self, result):
if is_error_result(result):
if result.type == 'item-not-found':
if result.condition == 'item-not-found':
self._create_muc(result.jid)
return
self._set_warning_from_error(result)
......
......@@ -20,6 +20,7 @@ from nbxmpp.util import is_error_result
from gajim.common import app
from gajim.common.i18n import _
from gajim.common.helpers import to_user_string
from gajim.common.const import MUC_DISCO_ERRORS
from gajim.gtk.groupchat_info import GroupChatInfoScrolled
......@@ -100,7 +101,7 @@ class GroupchatJoin(Gtk.ApplicationWindow):
self._stack.set_visible_child_name('error')
def _set_error(self, error):
text = MUC_DISCO_ERRORS.get(error.type, str(error))
text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error))
self._show_error_page(text)
def _set_error_from_code(self, error_code):
......
......@@ -19,6 +19,7 @@ from nbxmpp.util import is_error_result
from gajim.common import app
from gajim.common import ged
from gajim.common.i18n import _
from gajim.common.helpers import to_user_string
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import WarningDialog
......@@ -88,7 +89,7 @@ class ManagePEPServicesWindow(Gtk.ApplicationWindow):
def _items_received(self, result):
if is_error_result(result):
ErrorDialog('Error', str(result))
ErrorDialog('Error', to_user_string(result))
return
jid = result.jid.getBare()
......
......@@ -25,6 +25,7 @@ from nbxmpp.util import is_error_result
from gajim.common import app
from gajim.common import helpers
from gajim.common.helpers import validate_jid
from gajim.common.helpers import to_user_string
from gajim.common.i18n import _
from gajim.common.const import AvatarSize
from gajim.common.const import MUC_DISCO_ERRORS
......@@ -291,7 +292,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
self._set_error_from_code('not-muc-service')
def _set_error(self, error):
text = MUC_DISCO_ERRORS.get(error.type, str(error))
text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error))
self._show_error_page(text)
def _set_error_from_code(self, error_code):
......@@ -506,7 +507,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
def _parameters_received(self, result, user_data):
if is_error_result(result):
self._global_search_listbox.remove_progress()
self._show_error_page(result.message)
self._show_error_page(to_user_string(result))
return
con, text = user_data
......@@ -521,7 +522,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
if is_error_result(result):
self._global_search_listbox.remove_progress()
self._show_error_page(result.message)
self._show_error_page(to_user_string(result))
return
for item in result.items:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment