changeset 79ff4b0f478c in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=79ff4b0f478c
description: use NEC to handle privacy list events
diffstat:
src/common/connection.py | 49 +++++++++++++++++++++-
src/common/connection_handlers_events.py | 16 +++++++
src/dialogs.py | 45 +++++++++++++++++++-
src/groupchat_control.py | 6 +-
src/gui_interface.py | 68 --------------------------------
src/roster_window.py | 5 +-
6 files changed, 107 insertions(+), 82 deletions(-)
diffs (truncated from 331 to 300 lines):
diff -r 37a15ca4a190 -r 79ff4b0f478c src/common/connection.py
--- a/src/common/connection.py Wed Nov 24 17:28:18 2010 +0100
+++ b/src/common/connection.py Wed Nov 24 22:48:39 2010 +0100
@@ -712,8 +712,14 @@
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 @@
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 @@
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 @@
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 @@
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
diff -r 37a15ca4a190 -r 79ff4b0f478c src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py Wed Nov 24 17:28:18 2010 +0100
+++ b/src/common/connection_handlers_events.py Wed Nov 24 22:48:39 2010 +0100
@@ -1459,3 +1459,19 @@
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 = []
\ No newline at end of file
diff -r 37a15ca4a190 -r 79ff4b0f478c src/dialogs.py
--- a/src/dialogs.py Wed Nov 24 17:28:18 2010 +0100
+++ b/src/dialogs.py Wed Nov 24 22:48:39 2010 +0100
@@ -3864,6 +3864,11 @@
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 @@
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]
-
- def check_active_default(self, a_d_dict):
- if a_d_dict['active'] == self.privacy_list_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 _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 @@
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 @@
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 @@
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 @@
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 @@
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()
diff -r 37a15ca4a190 -r 79ff4b0f478c src/groupchat_control.py
--- a/src/groupchat_control.py Wed Nov 24 17:28:18 2010 +0100
+++ b/src/groupchat_control.py Wed Nov 24 22:48:39 2010 +0100
@@ -2576,9 +2576,9 @@
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():
diff -r 37a15ca4a190 -r 79ff4b0f478c src/gui_interface.py
--- a/src/gui_interface.py Wed Nov 24 17:28:18 2010 +0100
+++ b/src/gui_interface.py Wed Nov 24 22:48:39 2010 +0100
@@ -1210,68 +1210,6 @@
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)
-
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits