use NEC to handle privacy list events
This commit is contained in:
parent
3f781f5382
commit
6bdf47d7e7
|
@ -712,8 +712,14 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
self.private_storage_supported = True
|
||||
self.streamError = ''
|
||||
self.secret_hmac = str(random.random())[2:]
|
||||
gajim.ged.register_event_handler('privacy-list-received', ged.CORE,
|
||||
self._nec_privacy_list_received)
|
||||
# END __init__
|
||||
|
||||
def __del__(self):
|
||||
gajim.ged.remove_event_handler('privacy-list-received', ged.CORE,
|
||||
self._nec_privacy_list_received)
|
||||
|
||||
def get_config_values_or_default(self):
|
||||
if gajim.config.get_per('accounts', self.name, 'keep_alives_enabled'):
|
||||
self.keepalives = gajim.config.get_per('accounts', self.name,
|
||||
|
@ -895,7 +901,8 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
elif realm == common.xmpp.NS_PRIVACY:
|
||||
if event == common.xmpp.features_nb.PRIVACY_LISTS_RECEIVED:
|
||||
# data is (list)
|
||||
self.dispatch('PRIVACY_LISTS_RECEIVED', (data))
|
||||
gajim.nec.push_incoming_event(PrivacyListsReceivedEvent(None,
|
||||
conn=self, lists_list=data))
|
||||
elif event == common.xmpp.features_nb.PRIVACY_LIST_RECEIVED:
|
||||
# data is (resp)
|
||||
if not data:
|
||||
|
@ -916,10 +923,13 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
childs.append(scnd_child.getName())
|
||||
rules.append({'action':dict_item['action'],
|
||||
'order':dict_item['order'], 'child':childs})
|
||||
self.dispatch('PRIVACY_LIST_RECEIVED', (name, rules))
|
||||
gajim.nec.push_incoming_event(PrivacyListReceivedEvent(None,
|
||||
conn=self, list_name=name, rules=rules))
|
||||
elif event == common.xmpp.features_nb.PRIVACY_LISTS_ACTIVE_DEFAULT:
|
||||
# data is (dict)
|
||||
self.dispatch('PRIVACY_LISTS_ACTIVE_DEFAULT', (data))
|
||||
gajim.nec.push_incoming_event(PrivacyListActiveDefaultEvent(
|
||||
None, conn=self, active_list=data['active'],
|
||||
default_list=data['default']))
|
||||
|
||||
def _select_next_host(self, hosts):
|
||||
"""
|
||||
|
@ -1407,7 +1417,8 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
return
|
||||
def _on_del_privacy_list_result(result):
|
||||
if result:
|
||||
self.dispatch('PRIVACY_LIST_REMOVED', privacy_list)
|
||||
gajim.nec.push_incoming_event(PrivacyListRemovedEvent(None,
|
||||
conn=self, list_name=privacy_list))
|
||||
else:
|
||||
self.dispatch('ERROR', (_('Error while removing privacy list'),
|
||||
_('Privacy list %s has not been removed. It is maybe active in '
|
||||
|
@ -1878,6 +1889,36 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
iq2.setAttr('to', to)
|
||||
self.connection.send(iq)
|
||||
|
||||
def _nec_privacy_list_received(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
return
|
||||
if obj.list_name != 'block':
|
||||
return
|
||||
self.blocked_contacts = []
|
||||
self.blocked_groups = []
|
||||
self.blocked_list = []
|
||||
self.blocked_all = False
|
||||
for rule in obj.rules:
|
||||
if rule['action'] == 'allow':
|
||||
if not 'type' in rule:
|
||||
self.blocked_all = False
|
||||
elif rule['type'] == 'jid' and rule['value'] in \
|
||||
self.blocked_contacts:
|
||||
self.blocked_contacts.remove(rule['value'])
|
||||
elif rule['type'] == 'group' and rule['value'] in \
|
||||
self.blocked_groups:
|
||||
self.blocked_groups.remove(rule['value'])
|
||||
elif rule['action'] == 'deny':
|
||||
if not 'type' in rule:
|
||||
self.blocked_all = True
|
||||
elif rule['type'] == 'jid' and rule['value'] not in \
|
||||
self.blocked_contacts:
|
||||
self.blocked_contacts.append(rule['value'])
|
||||
elif rule['type'] == 'group' and rule['value'] not in \
|
||||
self.blocked_groups:
|
||||
self.blocked_groups.append(rule['value'])
|
||||
self.blocked_list.append(rule)
|
||||
|
||||
def _request_bookmarks_xml(self):
|
||||
if not gajim.account_is_connected(self.name):
|
||||
return
|
||||
|
|
|
@ -1459,3 +1459,19 @@ class UniqueRoomIdSupportedEvent(nec.NetworkIncomingEvent):
|
|||
class UniqueRoomIdNotSupportedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'unique-room-id-not-supported'
|
||||
base_network_events = []
|
||||
|
||||
class PrivacyListsReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'privacy-lists-received'
|
||||
base_network_events = []
|
||||
|
||||
class PrivacyListReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'privacy-list-received'
|
||||
base_network_events = []
|
||||
|
||||
class PrivacyListRemovedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'privacy-list-removed'
|
||||
base_network_events = []
|
||||
|
||||
class PrivacyListActiveDefaultEvent(nec.NetworkIncomingEvent):
|
||||
name = 'privacy-list-active-default'
|
||||
base_network_events = []
|
|
@ -3864,6 +3864,11 @@ class PrivacyListWindow:
|
|||
|
||||
self.window.set_title(title)
|
||||
|
||||
gajim.ged.register_event_handler('privacy-list-received', ged.GUI1,
|
||||
self._nec_privacy_list_received)
|
||||
gajim.ged.register_event_handler('privacy-list-active-default',
|
||||
ged.GUI1, self._nec_privacy_list_active_default)
|
||||
|
||||
self.window.show_all()
|
||||
self.add_edit_vbox.hide()
|
||||
|
||||
|
@ -3873,13 +3878,19 @@ class PrivacyListWindow:
|
|||
key_name = 'privacy_list_%s' % self.privacy_list_name
|
||||
if key_name in gajim.interface.instances[self.account]:
|
||||
del gajim.interface.instances[self.account][key_name]
|
||||
gajim.ged.remove_event_handler('privacy-list-received', ged.GUI1,
|
||||
self._nec_privacy_list_received)
|
||||
gajim.ged.remove_event_handler('privacy-list-active-default',
|
||||
ged.GUI1, self._nec_privacy_list_active_default)
|
||||
|
||||
def check_active_default(self, a_d_dict):
|
||||
if a_d_dict['active'] == self.privacy_list_name:
|
||||
def _nec_privacy_list_active_default(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
if obj.active_list == self.privacy_list_name:
|
||||
self.privacy_list_active_checkbutton.set_active(True)
|
||||
else:
|
||||
self.privacy_list_active_checkbutton.set_active(False)
|
||||
if a_d_dict['default'] == self.privacy_list_name:
|
||||
if obj.default_list == self.privacy_list_name:
|
||||
self.privacy_list_default_checkbutton.set_active(True)
|
||||
else:
|
||||
self.privacy_list_default_checkbutton.set_active(False)
|
||||
|
@ -3918,6 +3929,13 @@ class PrivacyListWindow:
|
|||
self.reset_fields()
|
||||
gajim.connections[self.account].get_active_default_lists()
|
||||
|
||||
def _nec_privacy_list_received(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
if obj.list_name != self.privacy_list_name:
|
||||
return
|
||||
self.privacy_list_received(obj.rules)
|
||||
|
||||
def refresh_rules(self):
|
||||
gajim.connections[self.account].get_privacy_list(self.privacy_list_name)
|
||||
|
||||
|
@ -4154,6 +4172,11 @@ class PrivacyListsWindow:
|
|||
|
||||
self.window.set_title(title)
|
||||
|
||||
gajim.ged.register_event_handler('privacy-lists-received', ged.GUI1,
|
||||
self._nec_privacy_lists_received)
|
||||
gajim.ged.register_event_handler('privacy-lists-removed', ged.GUI1,
|
||||
self._nec_privacy_lists_removed)
|
||||
|
||||
self.window.show_all()
|
||||
|
||||
self.xml.connect_signals(self)
|
||||
|
@ -4161,6 +4184,10 @@ class PrivacyListsWindow:
|
|||
def on_privacy_lists_first_window_destroy(self, widget):
|
||||
if 'privacy_lists' in gajim.interface.instances[self.account]:
|
||||
del gajim.interface.instances[self.account]['privacy_lists']
|
||||
gajim.ged.remove_event_handler('privacy-lists-received', ged.GUI1,
|
||||
self._nec_privacy_lists_received)
|
||||
gajim.ged.remove_event_handler('privacy-lists-removed', ged.GUI1,
|
||||
self._nec_privacy_lists_removed)
|
||||
|
||||
def remove_privacy_list_from_combobox(self, privacy_list):
|
||||
if privacy_list not in self.privacy_lists_save:
|
||||
|
@ -4206,6 +4233,11 @@ class PrivacyListsWindow:
|
|||
self.privacy_lists_save.remove(active_list)
|
||||
self.privacy_lists_received({'lists': self.privacy_lists_save})
|
||||
|
||||
def _nec_privacy_lists_removed(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
self.privacy_list_removed(obj.lists_list)
|
||||
|
||||
def privacy_lists_received(self, lists):
|
||||
if not lists:
|
||||
return
|
||||
|
@ -4214,6 +4246,11 @@ class PrivacyListsWindow:
|
|||
privacy_lists.append(privacy_list)
|
||||
self.draw_privacy_lists_in_combobox(privacy_lists)
|
||||
|
||||
def _nec_privacy_lists_received(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
self.privacy_lists_received(obj.lists_list)
|
||||
|
||||
def privacy_lists_refresh(self):
|
||||
gajim.connections[self.account].get_privacy_lists()
|
||||
|
||||
|
|
|
@ -2576,9 +2576,9 @@ class GroupchatControl(ChatControlBase):
|
|||
connection.set_default_list('')
|
||||
connection.set_active_list('')
|
||||
connection.del_privacy_list('block')
|
||||
if 'blocked_contacts' in gajim.interface.instances[self.account]:
|
||||
gajim.interface.instances[self.account]['blocked_contacts'].\
|
||||
privacy_list_received([])
|
||||
if 'privay_list_block' in gajim.interface.instances[self.account]:
|
||||
del gajim.interface.instances[self.account]\
|
||||
['privay_list_block']
|
||||
|
||||
def on_voice_checkmenuitem_activate(self, widget, nick):
|
||||
if widget.get_active():
|
||||
|
|
|
@ -1210,68 +1210,6 @@ class Interface:
|
|||
if ctrl:
|
||||
ctrl.begin_e2e_negotiation()
|
||||
|
||||
def handle_event_privacy_lists_received(self, account, data):
|
||||
# ('PRIVACY_LISTS_RECEIVED', account, list)
|
||||
if account not in self.instances:
|
||||
return
|
||||
if 'privacy_lists' in self.instances[account]:
|
||||
self.instances[account]['privacy_lists'].privacy_lists_received(
|
||||
data)
|
||||
|
||||
def handle_event_privacy_list_received(self, account, data):
|
||||
# ('PRIVACY_LIST_RECEIVED', account, (name, rules))
|
||||
if account not in self.instances:
|
||||
return
|
||||
name = data[0]
|
||||
rules = data[1]
|
||||
if 'privacy_list_%s' % name in self.instances[account]:
|
||||
self.instances[account]['privacy_list_%s' % name].\
|
||||
privacy_list_received(rules)
|
||||
if name == 'block':
|
||||
con = gajim.connections[account]
|
||||
con.blocked_contacts = []
|
||||
con.blocked_groups = []
|
||||
con.blocked_list = []
|
||||
gajim.connections[account].blocked_all = False
|
||||
for rule in rules:
|
||||
if rule['action'] == 'allow':
|
||||
if not 'type' in rule:
|
||||
con.blocked_all = False
|
||||
elif rule['type'] == 'jid' and rule['value'] in \
|
||||
con.blocked_contacts:
|
||||
con.blocked_contacts.remove(rule['value'])
|
||||
elif rule['type'] == 'group' and rule['value'] in \
|
||||
con.blocked_groups:
|
||||
con.blocked_groups.remove(rule['value'])
|
||||
elif rule['action'] == 'deny':
|
||||
if not 'type' in rule:
|
||||
con.blocked_all = True
|
||||
elif rule['type'] == 'jid' and rule['value'] not in \
|
||||
con.blocked_contacts:
|
||||
con.blocked_contacts.append(rule['value'])
|
||||
elif rule['type'] == 'group' and rule['value'] not in \
|
||||
con.blocked_groups:
|
||||
con.blocked_groups.append(rule['value'])
|
||||
con.blocked_list.append(rule)
|
||||
if 'blocked_contacts' in self.instances[account]:
|
||||
self.instances[account]['blocked_contacts'].\
|
||||
privacy_list_received(rules)
|
||||
|
||||
def handle_event_privacy_lists_active_default(self, account, data):
|
||||
if not data:
|
||||
return
|
||||
# Send to all privacy_list_* windows as we can't know which one asked
|
||||
for win in self.instances[account]:
|
||||
if win.startswith('privacy_list_'):
|
||||
self.instances[account][win].check_active_default(data)
|
||||
|
||||
def handle_event_privacy_list_removed(self, account, name):
|
||||
# ('PRIVACY_LISTS_REMOVED', account, name)
|
||||
if account not in self.instances:
|
||||
return
|
||||
if 'privacy_lists' in self.instances[account]:
|
||||
self.instances[account]['privacy_lists'].privacy_list_removed(name)
|
||||
|
||||
def handle_event_zc_name_conflict(self, account, data):
|
||||
def on_ok(new_name):
|
||||
gajim.config.set_per('accounts', account, 'name', new_name)
|
||||
|
@ -1619,12 +1557,6 @@ class Interface:
|
|||
'SIGNED_IN': [self.handle_event_signed_in],
|
||||
'METACONTACTS': [self.handle_event_metacontacts],
|
||||
'FAILED_DECRYPT': [self.handle_event_failed_decrypt],
|
||||
'PRIVACY_LISTS_RECEIVED': \
|
||||
[self.handle_event_privacy_lists_received],
|
||||
'PRIVACY_LIST_RECEIVED': [self.handle_event_privacy_list_received],
|
||||
'PRIVACY_LISTS_ACTIVE_DEFAULT': \
|
||||
[self.handle_event_privacy_lists_active_default],
|
||||
'PRIVACY_LIST_REMOVED': [self.handle_event_privacy_list_removed],
|
||||
'ZC_NAME_CONFLICT': [self.handle_event_zc_name_conflict],
|
||||
'PEP_CONFIG': [self.handle_event_pep_config],
|
||||
'PASSWORD_REQUIRED': [self.handle_event_password_required],
|
||||
|
|
|
@ -2887,9 +2887,8 @@ class RosterWindow:
|
|||
gajim.connections[account].set_default_list('')
|
||||
gajim.connections[account].set_active_list('')
|
||||
gajim.connections[account].del_privacy_list('block')
|
||||
if 'blocked_contacts' in gajim.interface.instances[account]:
|
||||
gajim.interface.instances[account]['blocked_contacts'].\
|
||||
privacy_list_received([])
|
||||
if 'privacy_list_block' in gajim.interface.instances[account]:
|
||||
del gajim.interface.instances[account]['privacy_list_block']
|
||||
for (contact, account) in list_:
|
||||
if not self.regroup:
|
||||
show = gajim.SHOW_LIST[gajim.connections[account].connected]
|
||||
|
|
Loading…
Reference in New Issue