Port some error messages to new interface

This commit is contained in:
Philipp Hörist 2017-12-08 20:19:10 +01:00
parent 61ad783658
commit 6926bdaee0
7 changed files with 57 additions and 28 deletions

View File

@ -177,10 +177,7 @@ class AccountsWindow(Gtk.ApplicationWindow):
def on_remove_account(self, button, account):
if app.events.get_events(account):
dialogs.ErrorDialog(
_('Unread events'),
_('Read all pending events before removing this account.'),
transient_for=self)
app.interface.raise_dialog('unread-events-on-remove')
return
if app.config.get_per('accounts', account, 'is_zeroconf'):
@ -361,10 +358,7 @@ class Account(Gtk.Box):
if (account in app.connections and
app.connections[account].connected > 0):
# connecting or connected
dialogs.ErrorDialog(
_('You are currently connected to the server'),
_('To disable the account, you must be disconnected.'),
transient_for=self.parent)
app.interface.raise_dialog('connected-on-disable-account')
switch.set_active(not state)
return
if state:

View File

@ -364,10 +364,8 @@ class CommandWindow:
if self.data_form_widget.get_data_form():
df = self.data_form_widget.get_data_form()
if not df.is_valid():
dialogs.ErrorDialog(
_('Invalid Form'),
_('The form is not filled correctly.'),
transient_for=self.window)
app.interface.raise_dialog(
'invalid-form', transient_for=self.window)
self.data_form_widget.set_sensitive(True)
return
self.data_form_widget.data_form.type_ = 'submit'

View File

@ -124,8 +124,7 @@ class AppActions():
account = param.get_string()
invisible_show = app.SHOW_LIST.index('invisible')
if app.connections[account].connected == invisible_show:
dialogs.ErrorDialog(_(
'You cannot join a group chat while you are invisible'))
app.interface.raise_dialog('join-while-invisible')
return
if 'join_gc' in interface.instances[account]:
interface.instances[account]['join_gc'].present()

View File

@ -694,8 +694,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if send_message and app.connections[self.account].connected < 2:
# we are not connected
dialogs.ErrorDialog(_('A connection is not available'),
_('Your message can not be sent until you are connected.'))
app.interface.raise_dialog('not-connected-while-sending')
elif send_message:
self.send_message(message, xhtml=xhtml)
else:

View File

@ -37,6 +37,7 @@ from gajim import dialogs
from gajim.common import dataforms
from gajim.common import helpers
from gajim.common import app
import itertools
@ -641,12 +642,10 @@ class SingleForm(Gtk.Table, object):
try:
newtext = helpers.parse_jid(newtext)
except helpers.InvalidFormat as s:
dialogs.ErrorDialog(_('Invalid JID'), str(s))
app.interface.raise_dialog('invalid-jid-with-error', str(s))
return
if newtext in field.values:
dialogs.ErrorDialog(
_('JID already in list'),
_('The JID you entered is already in the list. Choose another one.'))
app.interface.raise_dialog('jid-in-list')
GLib.idle_add(treeview.set_cursor, path)
return
model[path][0]=newtext

View File

@ -22,10 +22,52 @@ from collections import namedtuple
from gi.repository import GLib
from gajim.common.app import app
from gajim.dialogs import ErrorDialog
Message = namedtuple('Message', ['title', 'text', 'dialog'])
messages = {}
messages = {
'start-chat-not-connected': Message(
_('You are not connected to the server'),
_('You can not start a new conversation unless you are connected.'),
ErrorDialog),
'invalid-jid-with-error': Message(
_('Invalid JID'),
'%s',
ErrorDialog),
'unread-events-on-remove-account': Message(
_('Unread events'),
_('Read all pending events before removing this account.'),
ErrorDialog),
'connected-on-disable-account': Message(
_('You are currently connected to the server'),
_('To disable the account, you must be disconnected.'),
ErrorDialog),
'invalid-form': Message(
_('Invalid Form'),
_('The form is not filled correctly.'),
ErrorDialog),
'join-while-invisible': Message(
_('Invisible'),
_('You cannot join a group chat while you are invisible'),
ErrorDialog),
'not-connected-while-sending': Message(
_('A connection is not available'),
_('Your message can not be sent until you are connected.'),
ErrorDialog),
'jid-in-list': Message(
_('JID already in list'),
_('The JID you entered is already in the list. Choose another one.'),
ErrorDialog),
}
def get_dialog(name, *args, **kwargs):
@ -42,8 +84,10 @@ def get_dialog(name, *args, **kwargs):
if args:
message_text = message.text % args
else:
elif kwargs:
message_text = message.text % kwargs
else:
message_text = message.text
dialog = message.dialog(message.title,
GLib.markup_escape_text(message_text),
transient_for=transient_for)

View File

@ -2879,16 +2879,12 @@ class StartChatDialog(Gtk.ApplicationWindow):
def _start_new_chat(self, row):
if row.new:
if not app.account_is_connected(row.account):
ErrorDialog(
_('You are not connected to the server'),
_('You can not start a new conversation'
' unless you are connected.'),
transient_for=self)
app.interface.raise_dialog('start-chat-not-connected')
return
try:
helpers.parse_jid(row.jid)
except helpers.InvalidFormat as e:
ErrorDialog(_('Invalid JID'), str(e), transient_for=self)
app.interface.raise_dialog('invalid-jid-with-error', str(e))
return
if row.groupchat: