add presence events to trigger plugin
This commit is contained in:
parent
e93e1cef6e
commit
9d12023ec5
5 changed files with 113 additions and 59 deletions
|
@ -28,6 +28,15 @@
|
||||||
<row>
|
<row>
|
||||||
<col id="0" translatable="yes">Receive a Message</col>
|
<col id="0" translatable="yes">Receive a Message</col>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0" translatable="yes">Contact Connects</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0" translatable="yes">Contact Disconnects</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0" translatable="yes">Contact Changes Status</col>
|
||||||
|
</row>
|
||||||
</data>
|
</data>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkWindow" id="advanced_notifications_window">
|
<object class="GtkWindow" id="advanced_notifications_window">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[info]
|
[info]
|
||||||
name: Triggers
|
name: Triggers
|
||||||
short_name: triggers
|
short_name: triggers
|
||||||
version: 0.0.1
|
version: 0.0.2
|
||||||
description: Configure Gajim's behaviour for each contact
|
description: Configure Gajim's behaviour for each contact
|
||||||
authors: Yann Leboulanger <asterix@lagaule.org>
|
authors: Yann Leboulanger <asterix@lagaule.org>
|
||||||
homepage: http://trac.gajim.org/wiki/
|
homepage: http://trac.gajim.org/wiki/
|
||||||
|
|
|
@ -40,7 +40,8 @@ class Triggers(GajimPlugin):
|
||||||
|
|
||||||
self.events_handlers = {'notification' : (ged.PREGUI, self._nec_notif),
|
self.events_handlers = {'notification' : (ged.PREGUI, self._nec_notif),
|
||||||
'decrypted-message-received': (ged.PREGUI2,
|
'decrypted-message-received': (ged.PREGUI2,
|
||||||
self._nec_decrypted_message_received)}
|
self._nec_decrypted_message_received),
|
||||||
|
'presence-received': (ged.PREGUI, self._nec_presence_received)}
|
||||||
|
|
||||||
def _check_rule_recipients(self, obj, rule):
|
def _check_rule_recipients(self, obj, rule):
|
||||||
rule_recipients = [t.strip() for t in rule['recipients'].split(',')]
|
rule_recipients = [t.strip() for t in rule['recipients'].split(',')]
|
||||||
|
@ -80,50 +81,54 @@ class Triggers(GajimPlugin):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def check_rule_all(self, event, obj, rule):
|
||||||
|
# Check notification type
|
||||||
|
if rule['event'] != event:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# notification type is ok. Now check recipient
|
||||||
|
if not self._check_rule_recipients(obj, rule):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# recipient is ok. Now check our status
|
||||||
|
if not self._check_rule_status(obj, rule):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# our_status is ok. Now check opened chat window
|
||||||
|
if not self._check_rule_tab_opened(obj, rule):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# All is ok
|
||||||
|
return True
|
||||||
|
|
||||||
def check_rule_apply_notif(self, obj, rule):
|
def check_rule_apply_notif(self, obj, rule):
|
||||||
# Check notification type
|
# Check notification type
|
||||||
notif_type = ''
|
notif_type = ''
|
||||||
if obj.notif_type == 'msg':
|
if obj.notif_type == 'msg':
|
||||||
notif_type = 'message_received'
|
notif_type = 'message_received'
|
||||||
if notif_type != rule['event']:
|
elif obj.notif_type == 'pres':
|
||||||
return False
|
if obj.base_event.old_show < 2 and obj.base_event.new_show > 1:
|
||||||
|
notif_type = 'contact_connected'
|
||||||
|
elif obj.base_event.old_show > 1 and obj.base_event.new_show < 2:
|
||||||
|
notif_type = 'contact_disconnected'
|
||||||
|
else:
|
||||||
|
notif_type = 'contact_status_change'
|
||||||
|
|
||||||
# notification type is ok. Now check recipient
|
return self.check_rule_all(notif_type, obj, rule)
|
||||||
if not self._check_rule_recipients(obj, rule):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# recipient is ok. Now check our status
|
|
||||||
if not self._check_rule_status(obj, rule):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# our_status is ok. Now check opened chat window
|
|
||||||
if not self._check_rule_tab_opened(obj, rule):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# All is ok
|
|
||||||
return True
|
|
||||||
|
|
||||||
def check_rule_apply_decrypted_msg(self, obj, rule):
|
def check_rule_apply_decrypted_msg(self, obj, rule):
|
||||||
# Check notification type
|
return self.check_rule_all('message_received', obj, rule)
|
||||||
if rule['event'] != 'message_received':
|
|
||||||
return False
|
|
||||||
|
|
||||||
# notification type is ok. Now check recipient
|
def check_rule_apply_connected(self, obj, rule):
|
||||||
if not self._check_rule_recipients(obj, rule):
|
return self.check_rule_all('contact_connected', obj, rule)
|
||||||
return False
|
|
||||||
|
|
||||||
# recipient is ok. Now check our status
|
def check_rule_apply_disconnected(self, obj, rule):
|
||||||
if not self._check_rule_status(obj, rule):
|
return self.check_rule_all('contact_disconnected', obj, rule)
|
||||||
return False
|
|
||||||
|
|
||||||
# our_status is ok. Now check opened chat window
|
def check_rule_apply_status_changed(self, obj, rule):
|
||||||
if not self._check_rule_tab_opened(obj, rule):
|
return self.check_rule_all('contact_status_change', obj, rule)
|
||||||
return False
|
|
||||||
|
|
||||||
# All is ok
|
def apply_rule_notif(self, obj, rule):
|
||||||
return True
|
|
||||||
|
|
||||||
def apply_rule(self, obj, rule):
|
|
||||||
if rule['sound'] == 'no':
|
if rule['sound'] == 'no':
|
||||||
obj.do_sound = False
|
obj.do_sound = False
|
||||||
elif rule['sound'] == 'yes':
|
elif rule['sound'] == 'yes':
|
||||||
|
@ -156,32 +161,58 @@ class Triggers(GajimPlugin):
|
||||||
# ?? not in obj actions
|
# ?? not in obj actions
|
||||||
# elif rule['urgency_hint'] == 'yes':
|
# elif rule['urgency_hint'] == 'yes':
|
||||||
|
|
||||||
def _nec_notif(self, obj):
|
def apply_rule_decrypted_message(self, obj, rule):
|
||||||
# check rules in order
|
|
||||||
rules_num = [int(i) for i in self.config.keys()]
|
|
||||||
rules_num.sort()
|
|
||||||
for num in rules_num:
|
|
||||||
if self.check_rule_apply_notif(obj, self.config[str(num)]):
|
|
||||||
self.apply_rule(obj, self.config[str(num)])
|
|
||||||
# Should we stop after first valid rule ?
|
|
||||||
# break
|
|
||||||
|
|
||||||
def _nec_decrypted_message_received(self, obj):
|
|
||||||
rules_num = [int(i) for i in self.config.keys()]
|
|
||||||
rules_num.sort()
|
|
||||||
for num in rules_num:
|
|
||||||
rule = self.config[str(num)]
|
|
||||||
if self.check_rule_apply_decrypted_msg(obj, rule):
|
|
||||||
if rule['auto_open'] == 'no':
|
if rule['auto_open'] == 'no':
|
||||||
obj.popup = False
|
obj.popup = False
|
||||||
elif rule['auto_open'] == 'yes':
|
elif rule['auto_open'] == 'yes':
|
||||||
obj.popup = True
|
obj.popup = True
|
||||||
|
|
||||||
|
def apply_rule_presence(self, obj, rule):
|
||||||
|
if rule['auto_open'] == 'no':
|
||||||
|
obj.popup = False
|
||||||
|
elif rule['auto_open'] == 'yes':
|
||||||
|
obj.popup = True
|
||||||
|
|
||||||
|
def _nec_all(self, obj, check_func, apply_func):
|
||||||
|
# check rules in order
|
||||||
|
rules_num = [int(i) for i in self.config.keys()]
|
||||||
|
rules_num.sort()
|
||||||
|
for num in rules_num:
|
||||||
|
rule = self.config[str(num)]
|
||||||
|
if check_func(obj, rule):
|
||||||
|
apply_func(obj, rule)
|
||||||
|
# Should we stop after first valid rule ?
|
||||||
|
# break
|
||||||
|
|
||||||
|
def _nec_notif(self, obj):
|
||||||
|
self._nec_all(obj, self.check_rule_apply_notif, self.apply_rule_notif)
|
||||||
|
|
||||||
|
def _nec_decrypted_message_received(self, obj):
|
||||||
|
self._nec_all(obj, self.check_rule_apply_decrypted_msg,
|
||||||
|
self.apply_rule_decrypted_message)
|
||||||
|
|
||||||
|
def _nec_presence_received(self, obj):
|
||||||
|
if obj.old_show < 2 and obj.new_show > 1:
|
||||||
|
check_func = self.check_rule_apply_connected
|
||||||
|
elif obj.old_show > 1 and obj.new_show < 2:
|
||||||
|
check_func = self.check_rule_apply_disconnected
|
||||||
|
else:
|
||||||
|
check_func = self.check_rule_apply_status_changed
|
||||||
|
self._nec_all(obj, check_func, self.apply_rule_presence)
|
||||||
|
|
||||||
|
|
||||||
class TriggersPluginConfigDialog(GajimPluginConfigDialog):
|
class TriggersPluginConfigDialog(GajimPluginConfigDialog):
|
||||||
events_list = ['message_received']#, 'contact_connected',
|
# {event: widgets_to_disable, }
|
||||||
#'contact_disconnected', 'contact_change_status', 'gc_msg_highlight',
|
events_list = {
|
||||||
#'gc_msg']
|
'message_received': [],
|
||||||
|
'contact_connected': ['use_systray_cb', 'disable_systray_cb',
|
||||||
|
'use_roster_cb', 'disable_roster_cb'],
|
||||||
|
'contact_disconnected': ['use_systray_cb', 'disable_systray_cb',
|
||||||
|
'use_roster_cb', 'disable_roster_cb'],
|
||||||
|
'contact_status_change': ['use_systray_cb', 'disable_systray_cb',
|
||||||
|
'use_roster_cb', 'disable_roster_cb']
|
||||||
|
#, 'gc_msg_highlight': [], 'gc_msg': []}
|
||||||
|
}
|
||||||
recipient_types_list = ['contact', 'group', 'all']
|
recipient_types_list = ['contact', 'group', 'all']
|
||||||
config_options = ['event', 'recipient_type', 'recipients', 'status',
|
config_options = ['event', 'recipient_type', 'recipients', 'status',
|
||||||
'tab_opened', 'sound', 'sound_file', 'popup', 'auto_open',
|
'tab_opened', 'sound', 'sound_file', 'popup', 'auto_open',
|
||||||
|
@ -278,7 +309,7 @@ class TriggersPluginConfigDialog(GajimPluginConfigDialog):
|
||||||
# event
|
# event
|
||||||
value = self.config[self.active_num]['event']
|
value = self.config[self.active_num]['event']
|
||||||
if value:
|
if value:
|
||||||
self.event_combobox.set_active(self.events_list.index(value))
|
self.event_combobox.set_active(self.events_list.keys().index(value))
|
||||||
else:
|
else:
|
||||||
self.event_combobox.set_active(-1)
|
self.event_combobox.set_active(-1)
|
||||||
# recipient_type
|
# recipient_type
|
||||||
|
@ -449,8 +480,14 @@ class TriggersPluginConfigDialog(GajimPluginConfigDialog):
|
||||||
if active == -1:
|
if active == -1:
|
||||||
event = ''
|
event = ''
|
||||||
else:
|
else:
|
||||||
event = self.events_list[active]
|
event = self.events_list.keys()[active]
|
||||||
self.config[self.active_num]['event'] = event
|
self.config[self.active_num]['event'] = event
|
||||||
|
for w in ('use_systray_cb', 'disable_systray_cb', 'use_roster_cb',
|
||||||
|
'disable_roster_cb'):
|
||||||
|
self.__dict__[w].set_sensitive(True)
|
||||||
|
for w in self.events_list[event]:
|
||||||
|
self.__dict__[w].set_sensitive(False)
|
||||||
|
self.__dict__[w].set_state(False)
|
||||||
self.set_treeview_string()
|
self.set_treeview_string()
|
||||||
|
|
||||||
def on_recipient_type_combobox_changed(self, widget):
|
def on_recipient_type_combobox_changed(self, widget):
|
||||||
|
|
|
@ -711,6 +711,8 @@ PresenceHelperEvent):
|
||||||
self.need_add_in_roster = False
|
self.need_add_in_roster = False
|
||||||
self.need_redraw = False
|
self.need_redraw = False
|
||||||
|
|
||||||
|
self.popup = False # Do we want to open chat window ?
|
||||||
|
|
||||||
if not self.conn or self.conn.connected < 2:
|
if not self.conn or self.conn.connected < 2:
|
||||||
log.debug('account is no more connected')
|
log.debug('account is no more connected')
|
||||||
return
|
return
|
||||||
|
|
|
@ -2487,6 +2487,15 @@ class RosterWindow:
|
||||||
if obj.contact:
|
if obj.contact:
|
||||||
self.chg_contact_status(obj.contact, obj.show, obj.status, account)
|
self.chg_contact_status(obj.contact, obj.show, obj.status, account)
|
||||||
|
|
||||||
|
if obj.popup:
|
||||||
|
ctrl = gajim.interface.msg_win_mgr.search_control(jid, account)
|
||||||
|
if ctrl:
|
||||||
|
gobject.idle_add(ctrl.parent_win.set_active_tab, ctrl)
|
||||||
|
else:
|
||||||
|
ctrl = gajim.interface.new_chat(obj.contact, account)
|
||||||
|
if len(gajim.events.get_events(account, obj.jid)):
|
||||||
|
ctrl.read_queue()
|
||||||
|
|
||||||
def _nec_gc_presence_received(self, obj):
|
def _nec_gc_presence_received(self, obj):
|
||||||
account = obj.conn.name
|
account = obj.conn.name
|
||||||
if obj.room_jid in gajim.interface.minimized_controls[account]:
|
if obj.room_jid in gajim.interface.minimized_controls[account]:
|
||||||
|
@ -2580,12 +2589,9 @@ class RosterWindow:
|
||||||
if obj.msg_id:
|
if obj.msg_id:
|
||||||
gajim.logger.set_read_messages([obj.msg_id])
|
gajim.logger.set_read_messages([obj.msg_id])
|
||||||
elif obj.popup:
|
elif obj.popup:
|
||||||
if not obj.session.control:
|
contact = gajim.contacts.get_contact(obj.conn.name, obj.jid)
|
||||||
contact = gajim.contacts.get_contact(obj.conn.name, obj.jid,
|
|
||||||
obj.resource_for_chat)
|
|
||||||
obj.session.control = gajim.interface.new_chat(contact,
|
obj.session.control = gajim.interface.new_chat(contact,
|
||||||
obj.conn.name, resource=obj.resource_for_chat,
|
obj.conn.name, session=obj.session)
|
||||||
session=obj.session)
|
|
||||||
if len(gajim.events.get_events(obj.conn.name, obj.fjid)):
|
if len(gajim.events.get_events(obj.conn.name, obj.fjid)):
|
||||||
obj.session.control.read_queue()
|
obj.session.control.read_queue()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue