changeset 76f9ccbd1369 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=76f9ccbd1369
description: new way to handle incominf messages, new notification event.
diffstat:
plugins/snarl_notifications/plugin.py | 25 +----
src/chat_control.py | 2 +-
src/common/connection_handlers.py | 1 +
src/common/connection_handlers_events.py | 154 +++++++++++++++++++++++++++++
src/common/gajim.py | 3 +
src/common/ged.py | 17 ++-
src/common/nec.py | 8 +-
src/disco.py | 1 -
src/groupchat_control.py | 23 +++-
src/notify.py | 27 +++++
src/roster_window.py | 40 +++++++
src/session.py | 162 ++++++++++++++++++------------
12 files changed, 362 insertions(+), 101 deletions(-)
diffs (truncated from 677 to 300 lines):
diff -r 4522e590db27 -r 76f9ccbd1369 plugins/snarl_notifications/plugin.py
--- a/plugins/snarl_notifications/plugin.py Sun May 01 18:31:44 2011 +0200
+++ b/plugins/snarl_notifications/plugin.py Sun May 01 22:09:50 2011 +0200
@@ -45,7 +45,7 @@
#self.gui_extension_points = {}
#self.config_default_values = {}
- self.events_handlers = {'NewMessage' : (ged.POSTCORE, self.newMessage)}
+ self.events_handlers = {'notification' : (ged.POSTCORE, self.notif)}
@log_calls('SnarlNotificationsPlugin')
def activate(self):
@@ -56,29 +56,12 @@
pass
@log_calls('SnarlNotificationsPlugin')
- def newMessage(self, args):
- event_name = "NewMessage"
- data = args
- account = data[0]
- jid = data[1][0]
- jid_without_resource = gajim.get_jid_without_resource(jid)
- msg = data[1][1]
- msg_type = data[1][4]
- if msg_type == 'chat':
- nickname = gajim.get_contact_name_from_jid(account,
jid_without_resource)
- elif msg_type in ('pm', 'groupchat'):
- nickname = gajim.get_resource_from_jid(jid)
- else:
- nickname = jid
-
- print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name,
pformat(args))
- print "Event '%s' occured. Arguments: \naccount = %s\njid = %s\nmsg =
%s\nnickname = %s"%(
- event_name, account, jid, msg, nickname)
-
+ def notif(self, obj):
+ print "Event '%s' occured.\n\n===\n" % obj.popup_event_type
#if PySnarl.snGetVersion() != False:
#(major, minor) = PySnarl.snGetVersion()
#print "Found Snarl version",str(major)+"."+str(minor),"running."
- #PySnarl.snShowMessage(nickname, msg[:20]+'...')
+ #PySnarl.snShowMessage(obj.popup_title, obj.popup_text)
#else:
#print "Sorry Snarl does not appear to be running"
diff -r 4522e590db27 -r 76f9ccbd1369 src/chat_control.py
--- a/src/chat_control.py Sun May 01 18:31:44 2011 +0200
+++ b/src/chat_control.py Sun May 01 22:09:50 2011 +0200
@@ -2954,7 +2954,7 @@
if len(data) > 6 and isinstance(data[6], int):
message_ids.append(data[6])
- if len(data) > 8:
+ if len(data) > 8 and not self.session:
self.set_session(data[8])
if message_ids:
gajim.logger.set_read_messages(message_ids)
diff -r 4522e590db27 -r 76f9ccbd1369 src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Sun May 01 18:31:44 2011 +0200
+++ b/src/common/connection_handlers.py Sun May 01 22:09:50 2011 +0200
@@ -1240,6 +1240,7 @@
gajim.nec.register_incoming_event(ArchivingErrorReceivedEvent)
gajim.nec.register_incoming_event(
ArchivingPreferencesChangedReceivedEvent)
+ gajim.nec.register_incoming_event(NotificationEvent)
gajim.ged.register_event_handler('http-auth-received', ged.CORE,
self._nec_http_auth_received)
diff -r 4522e590db27 -r 76f9ccbd1369 src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py Sun May 01 18:31:44 2011 +0200
+++ b/src/common/connection_handlers_events.py Sun May 01 22:09:50 2011 +0200
@@ -35,6 +35,8 @@
from common.logger import LOG_DB_PATH
from common.pep import SUPPORTED_PERSONAL_USER_EVENTS
+import gtkgui_helpers
+
import logging
log = logging.getLogger('gajim.c.connection_handlers_events')
@@ -1888,3 +1890,155 @@
self.prompt = None
self.prompt_jid = None
return True
+
+class NotificationEvent(nec.NetworkIncomingEvent):
+ name = 'notification'
+ base_network_events = ['decrypted-message-received', 'gc-message-received']
+
+ def detect_type(self):
+ if self.base_event.name == 'decrypted-message-received':
+ self.notif_type = 'msg'
+ if self.base_event.name == 'gc-message-received':
+ self.notif_type = 'gc-msg'
+
+ def get_focused(self):
+ self.control_focused = False
+ if self.control:
+ parent_win = self.control.parent_win
+ if parent_win and self.control == parent_win.get_active_control() \
+ and parent_win.window.has_focus:
+ self.control_focused = True
+
+ def handle_incoming_msg_event(self, msg_obj):
+ if not msg_obj.msgtxt:
+ return
+ self.jid = msg_obj.jid
+ if msg_obj.session:
+ self.control = msg_obj.session.control
+ else:
+ self.control = None
+ self.get_focused()
+ # This event has already been added to event list
+ if not self.control and len(gajim.events.get_events(self.conn.name, \
+ self.jid, [msg_obj.mtype])) <= 1:
+ self.first_unread = True
+
+ if msg_obj.mtype == 'pm':
+ nick = msg_obj.resource
+ else:
+ nick = gajim.get_name_from_jid(self.conn.name, self.jid)
+
+ if self.first_unread:
+ self.sound_event = 'first_message_received'
+ elif self.control_focused:
+ self.sound_event = 'next_message_received_focused'
+ else:
+ self.sound_event = 'next_message_received_unfocused'
+
+ if gajim.config.get('notification_preview_message'):
+ self.popup_text = msg_obj.msgtxt
+ if self.popup_text and (self.popup_text.startswith('/me ') or \
+ self.popup_text.startswith('/me\n')):
+ self.popup_text = '* ' + nick + self.popup_text[3:]
+ else:
+ # We don't want message preview, do_preview = False
+ self.popup_text = ''
+ if msg_obj.mtype == 'normal': # single message
+ self.popup_event_type = _('New Single Message')
+ self.popup_image = 'gajim-single_msg_recv'
+ self.popup_title = _('New Single Message from %(nickname)s') % \
+ {'nickname': nick}
+ elif msg_obj.mtype == 'pm':
+ self.popup_event_type = _('New Private Message')
+ self.popup_image = 'gajim-priv_msg_recv'
+ self.popup_title = _('New Private Message from group chat %s') % \
+ msg_obj.jid
+ if self.popup_text:
+ self.popup_text = _('%(nickname)s: %(message)s') % \
+ {'nickname': nick, 'message': self.popup_text}
+ else:
+ self.popup_text = _('Messaged by %(nickname)s') % \
+ {'nickname': nick}
+ else: # chat message
+ self.popup_event_type = _('New Message')
+ self.popup_image = 'gajim-chat_msg_recv'
+ self.popup_title = _('New Message from %(nickname)s') % \
+ {'nickname': nick}
+
+ self.popup_image = gtkgui_helpers.get_icon_path(self.popup_image, 48)
+
+ if not gajim.config.get('notify_on_new_message') or \
+ not self.first_unread:
+ self.do_popup = False
+ elif gajim.config.get('autopopupaway'):
+ # always show notification
+ self.do_popup = True
+ elif gajim.connections[self.conn.name].connected in (2, 3):
+ # we're online or chat
+ self.do_popup = True
+
+ if self.first_unread and helpers.allow_sound_notification(
+ self.conn.name, 'first_message_received'):
+ self.do_sound = True
+ elif not self.first_unread and self.control_focused and \
+ helpers.allow_sound_notification(self.conn.name,
+ 'next_message_received_focused'):
+ self.do_sound = True
+ elif not self.first_unread and not self.control_focused and \
+ helpers.allow_sound_notification(self.conn.name,
+ 'next_message_received_unfocused'):
+ self.do_sound = True
+
+ def handle_incoming_gc_msg_event(self, msg_obj):
+ sound = msg_obj.msg_obj.gc_control.highlighting_for_message(
+ msg_obj.msgtxt, msg_obj.timestamp)[1]
+ self.do_sound = True
+ if sound == 'received':
+ self.sound_event = 'muc_message_received'
+ elif sound == 'highlight':
+ self.sound_event = 'muc_message_highlight'
+ else:
+ self.do_sound = False
+
+ self.do_popup = False
+
+ def handle_incoming_pres_event(self, msg_obj):
+ pass
+
+ def generate(self):
+ # what's needed to compute output
+ self.conn = self.base_event.conn
+ self.control = None
+ self.control_focused = False
+ self.first_unread = False
+
+ # For output
+ self.do_sound = False
+ self.sound_file = ''
+ self.sound_event = '' # gajim sound played if not sound_file is set
+ self.show_popup = False
+
+ self.do_popup = False
+ self.popup_title = ''
+ self.popup_text = ''
+ self.popup_event_type = ''
+ self.popup_msg_type = ''
+ self.popup_image = ''
+
+ self.do_command = False
+ self.command = ''
+
+ self.open_chat = False
+ self.activate_urgency_hint = False
+ self.show_in_notification_area = False
+ self.show_in_roster = False
+
+ self.detect_type()
+
+ if self.notif_type == 'msg':
+ self.handle_incoming_msg_event(self.base_event)
+ elif self.notif_type == 'gc-msg':
+ self.handle_incoming_gc_msg_event(self.base_event)
+ elif self.notif_type == 'pres':
+ self.handle_incoming_pres_event(self.base_event)
+ return True
diff -r 4522e590db27 -r 76f9ccbd1369 src/common/gajim.py
--- a/src/common/gajim.py Sun May 01 18:31:44 2011 +0200
+++ b/src/common/gajim.py Sun May 01 22:09:50 2011 +0200
@@ -35,6 +35,7 @@
import xmpp
import defs
import common.ged
+import notify
interface = None # The actual interface (the gtk one for the moment)
thread_interface = None # Interface to run a thread and then a callback
@@ -105,6 +106,8 @@
events = Events()
+notification = notify.Notification()
+
nicks = {} # list of our nick names in each account
# should we block 'contact signed in' notifications for this account?
# this is only for the first 30 seconds after we change our show
diff -r 4522e590db27 -r 76f9ccbd1369 src/common/ged.py
--- a/src/common/ged.py Sun May 01 18:31:44 2011 +0200
+++ b/src/common/ged.py Sun May 01 22:09:50 2011 +0200
@@ -27,12 +27,17 @@
import logging
log = logging.getLogger('gajim.common.ged')
-PRECORE = 30
-CORE = 40
-POSTCORE = 50
+PRECORE = 10
+CORE = 20
+POSTCORE = 30
+PREGUI = 40
+PREGUI1 = 50
GUI1 = 60
-GUI2 = 70
-POSTGUI = 80
+POSTGUI1 = 70
+PREGUI2 = 80
+GUI2 = 90
+POSTGUI2 = 100
+POSTGUI = 110
class GlobalEventsDispatcher(object):
@@ -68,4 +73,4 @@
if event_name in self.handlers:
for priority, handler in self.handlers[event_name]:
if handler(*args, **kwargs):
- return
+ return True
diff -r 4522e590db27 -r 76f9ccbd1369 src/common/nec.py
--- a/src/common/nec.py Sun May 01 18:31:44 2011 +0200
+++ b/src/common/nec.py Sun May 01 22:09:50 2011 +0200
@@ -58,8 +58,8 @@
def push_incoming_event(self, event_object):
if event_object.generate():
- gajim.ged.raise_event(event_object.name, event_object)
- self._generate_events_based_on_incoming_event(event_object)
+ if not gajim.ged.raise_event(event_object.name, event_object):
+ self._generate_events_based_on_incoming_event(event_object)
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits