Commit 0cba9f53 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

XML Console: Make accounts selectable

parent 3b1f1cd5
Pipeline #4330 passed with stages
in 2 minutes and 33 seconds
......@@ -249,12 +249,8 @@ def on_server_info(action, param):
def on_xml_console(action, param):
account = param.get_string()
window = app.get_app_window(XMLConsoleWindow, account)
if window is None:
XMLConsoleWindow(account)
else:
window.present()
XMLConsoleWindow()
def on_manage_proxies(action, param):
......
......@@ -431,6 +431,7 @@ class GajimApplication(Gtk.Application):
('history-manager', app_actions.on_history_manager),
('preferences', app_actions.on_preferences),
('plugins', app_actions.on_plugins),
('xml-console', app_actions.on_xml_console),
('file-transfer', app_actions.on_file_transfers),
('history', app_actions.on_history),
('shortcuts', app_actions.on_keyboard_shortcuts),
......@@ -496,9 +497,7 @@ class GajimApplication(Gtk.Application):
from gajim import app_actions as a
if account == 'Local':
return [
('-xml-console', a.on_xml_console, 'always', 's')
]
return []
return [
('-bookmarks', a.on_bookmarks, 'online', 's'),
......@@ -507,7 +506,6 @@ class GajimApplication(Gtk.Application):
('-add-contact', a.on_add_contact, 'online', 'as'),
('-services', a.on_service_disco, 'online', 's'),
('-profile', a.on_profile, 'feature', 's'),
('-xml-console', a.on_xml_console, 'always', 's'),
('-server-info', a.on_server_info, 'online', 's'),
('-archive', a.on_mam_preferences, 'feature', 's'),
('-pep-config', a.on_pep_config, 'online', 's'),
......
......@@ -28,6 +28,11 @@
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">XML Console</attribute>
<attribute name="action">app.xml-console</attribute>
<attribute name="accel">&lt;Primary&gt;&lt;Shift&gt;X</attribute>
</item>
<item>
<attribute name="label" translatable="yes">File Transfer</attribute>
<attribute name="action">app.file-transfer</attribute>
......
......@@ -75,16 +75,12 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">XML Console</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkSwitch">
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="active">True</property>
<signal name="notify::active" handler="_on_enable" swapped="no"/>
<property name="can_focus">False</property>
<property name="icon_name">utilities-terminal-symbolic</property>
</object>
</child>
</object>
......
......@@ -35,7 +35,7 @@ from gajim.gtk.const import SettingType
class XMLConsoleWindow(Gtk.ApplicationWindow):
def __init__(self, account):
def __init__(self):
Gtk.ApplicationWindow.__init__(self)
self.set_application(app.app)
self.set_position(Gtk.WindowPosition.CENTER)
......@@ -44,8 +44,7 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
self.set_show_menubar(False)
self.set_name('XMLConsoleWindow')
self.account = account
self.enabled = True
self.selected_account = None
self.presence = True
self.message = True
self.iq = True
......@@ -55,24 +54,21 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
self.filter_dialog = None
self.last_stanza = None
self._ui = get_builder('xml_console_window.ui')
jid = app.get_jid_from_account(account)
self._ui = get_builder('xml_console.ui')
self.set_titlebar(self._ui.headerbar)
self._ui.headerbar.set_subtitle(jid)
self._set_titlebar()
self.add(self._ui.box)
self._ui.paned.set_position(self._ui.paned.get_property('max-position'))
button = get_image_button(
'edit-clear-all-symbolic', _('Clear'))
button.connect('clicked', self._on_clear)
'applications-system-symbolic', _('Filter'))
button.connect('clicked', self._on_filter_options)
self._ui.actionbar.pack_start(button)
button = get_image_button(
'applications-system-symbolic', _('Filter'))
button.connect('clicked', self._on_filter_options)
'edit-clear-symbolic', _('Clear'))
button.connect('clicked', self._on_clear)
self._ui.actionbar.pack_start(button)
button = get_image_button(
......@@ -84,7 +80,7 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
button.connect('clicked', self._on_paste_last)
self._ui.actionbar.pack_start(button)
button = get_image_button('mail-send-symbolic', _('Send'))
button = Gtk.Button.new_with_mnemonic(_('_Send'))
button.connect('clicked', self._on_send)
self._ui.actionbar.pack_end(button)
......@@ -105,6 +101,13 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
app.ged.register_event_handler(
'stanza-sent', ged.GUI1, self._nec_stanza_sent)
def _set_titlebar(self):
if self.selected_account is None:
title = _('All Accounts')
else:
title = app.get_jid_from_account(self.selected_account)
self._ui.headerbar.set_subtitle(title)
def _create_tags(self):
buffer_ = self._ui.textview.get_buffer()
in_color = app.css_config.get_value(
......@@ -160,12 +163,12 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
self._ui.input_entry.grab_focus()
def _on_send(self, *args):
if not app.account_is_connected(self.account):
if not app.account_is_connected(self.selected_account):
# If offline or connecting
ErrorDialog(
_('Connection not available'),
_('Please make sure you are connected with \'%s\'.') %
self.account)
self.selected_account)
return
buffer_ = self._ui.input_entry.get_buffer()
begin_iter, end_iter = buffer_.get_bounds()
......@@ -184,7 +187,7 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
# stream management
node = nbxmpp.Protocol(node=stanza,
attrs={'xmlns': 'jabber:client'})
app.connections[self.account].connection.send(node)
app.connections[self.selected_account].connection.send(node)
self.last_stanza = stanza
buffer_.set_text('')
......@@ -207,32 +210,46 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
if self.filter_dialog:
self.filter_dialog.present()
return
options = [
# Get all accounts for settings combobox
accounts = app.get_accounts_sorted()
combo_accounts = []
for account in accounts:
label = app.get_account_label(account)
combo_accounts.append((account, label))
combo_accounts.insert(0, (None, _('All Accounts')))
settings = [
Setting(SettingKind.COMBO, _('Account'),
SettingType.VALUE, self.selected_account,
callback=self._set_account,
props={'combo_items': combo_accounts}),
Setting(SettingKind.SWITCH, 'Presence',
SettingType.VALUE, self.presence,
callback=self._on_option, data='presence'),
callback=self._on_setting, data='presence'),
Setting(SettingKind.SWITCH, 'Message',
SettingType.VALUE, self.message,
callback=self._on_option, data='message'),
callback=self._on_setting, data='message'),
Setting(SettingKind.SWITCH, 'IQ', SettingType.VALUE, self.iq,
callback=self._on_option, data='iq'),
callback=self._on_setting, data='iq'),
Setting(SettingKind.SWITCH, 'Stream Management',
SettingType.VALUE, self.stream,
callback=self._on_option, data='stream'),
callback=self._on_setting, data='stream'),
Setting(SettingKind.SWITCH, 'In', SettingType.VALUE, self.incoming,
callback=self._on_option, data='incoming'),
callback=self._on_setting, data='incoming'),
Setting(SettingKind.SWITCH, 'Out', SettingType.VALUE, self.outgoing,
callback=self._on_option, data='outgoing'),
callback=self._on_setting, data='outgoing'),
]
self.filter_dialog = SettingsDialog(self, 'Filter',
self.filter_dialog = SettingsDialog(self, _('Filter'),
Gtk.DialogFlags.DESTROY_WITH_PARENT,
options, self.account)
settings, self.selected_account)
self.filter_dialog.connect('destroy', self._on_filter_destroyed)
def _on_filter_destroyed(self, win):
......@@ -247,10 +264,11 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
app.ged.remove_event_handler(
'stanza-sent', ged.GUI1, self._nec_stanza_sent)
def _on_enable(self, switch, param):
self.enabled = switch.get_active()
def _set_account(self, value, data):
self.selected_account = value
self._set_titlebar()
def _on_option(self, value, data):
def _on_setting(self, value, data):
setattr(self, data, value)
value = not value
table = self._ui.textview.get_buffer().get_tag_table()
......@@ -263,19 +281,21 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
tag.set_property('invisible', value)
def _nec_stanza_received(self, obj):
if obj.conn.name != self.account:
return
self._print_stanza(obj.stanza_str, 'incoming')
if self.selected_account is not None:
if obj.conn.name != self.selected_account:
return
self._print_stanza(obj, 'incoming')
def _nec_stanza_sent(self, obj):
if obj.conn.name != self.account:
return
self._print_stanza(obj.stanza_str, 'outgoing')
if self.selected_account is not None:
if obj.conn.name != self.selected_account:
return
self._print_stanza(obj, 'outgoing')
def _print_stanza(self, stanza, kind):
def _print_stanza(self, obj, kind):
account = app.get_jid_from_account(obj.conn.name)
stanza = obj.stanza_str
# Kind must be 'incoming' or 'outgoing'
if not self.enabled:
return
if not stanza:
return
......@@ -294,9 +314,10 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
elif stanza.startswith('<r') or stanza.startswith('<a'):
type_ = 'stream'
stanza = '<!-- {kind} {time} -->\n{stanza}\n\n'.format(
stanza = '<!-- {kind} {time} ({account}) -->\n{stanza}\n\n'.format(
kind=kind.capitalize(),
time=time.strftime('%c'),
account=account,
stanza=stanza.replace('><', '>\n<'))
buffer_.insert_with_tags_by_name(end_iter, stanza, type_, kind)
......
......@@ -678,8 +678,6 @@ def get_account_menu(account):
('-pep-config', _('PEP Configuration')),
('-sync-history', _('Synchronise History')),
('-privacylists', _('Privacy Lists')),
('-xml-console', _('XML Console'))
]),
(_('Admin'), [
('-send-server-message', _('Send Server Message…')),
......@@ -689,10 +687,6 @@ def get_account_menu(account):
]),
]
zeroconf_menu = [
('-xml-console', _('XML Console')),
]
def build_menu(preset):
menu = Gio.Menu()
for item in preset:
......@@ -713,8 +707,6 @@ def get_account_menu(account):
menu.append_submenu(label, submenu)
return menu
if account == 'Local':
return build_menu(zeroconf_menu)
return build_menu(account_menu)
......@@ -741,8 +733,9 @@ def build_accounts_menu():
acc_menu.append_item(modify_account_item)
for acc in accounts_list:
label = escape_mnemonic(app.get_account_label(acc))
acc_menu.append_submenu(
label, get_account_menu(acc))
if acc != 'Local':
acc_menu.append_submenu(
label, get_account_menu(acc))
else:
acc_menu = get_account_menu(accounts_list[0])
modify_account_item = Gio.MenuItem.new(_('_Modify Account…'),
......
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