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

View File

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

View File

@ -124,8 +124,7 @@ class AppActions():
account = param.get_string() account = param.get_string()
invisible_show = app.SHOW_LIST.index('invisible') invisible_show = app.SHOW_LIST.index('invisible')
if app.connections[account].connected == invisible_show: if app.connections[account].connected == invisible_show:
dialogs.ErrorDialog(_( app.interface.raise_dialog('join-while-invisible')
'You cannot join a group chat while you are invisible'))
return return
if 'join_gc' in interface.instances[account]: if 'join_gc' in interface.instances[account]:
interface.instances[account]['join_gc'].present() 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: if send_message and app.connections[self.account].connected < 2:
# we are not connected # we are not connected
dialogs.ErrorDialog(_('A connection is not available'), app.interface.raise_dialog('not-connected-while-sending')
_('Your message can not be sent until you are connected.'))
elif send_message: elif send_message:
self.send_message(message, xhtml=xhtml) self.send_message(message, xhtml=xhtml)
else: else:

View File

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

View File

@ -22,10 +22,52 @@ from collections import namedtuple
from gi.repository import GLib from gi.repository import GLib
from gajim.common.app import app from gajim.common.app import app
from gajim.dialogs import ErrorDialog
Message = namedtuple('Message', ['title', 'text', 'dialog']) 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): def get_dialog(name, *args, **kwargs):
@ -42,8 +84,10 @@ def get_dialog(name, *args, **kwargs):
if args: if args:
message_text = message.text % args message_text = message.text % args
else: elif kwargs:
message_text = message.text % kwargs message_text = message.text % kwargs
else:
message_text = message.text
dialog = message.dialog(message.title, dialog = message.dialog(message.title,
GLib.markup_escape_text(message_text), GLib.markup_escape_text(message_text),
transient_for=transient_for) transient_for=transient_for)

View File

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