Changeset 6318

Show
Ignore:
Timestamp:
05/10/06 22:25:51 (3 years ago)
Author:
jim++
Message:

#1005 preparation : Begin to move notifications to notify.py :
-moved popup and sound for contact in/out
-added popup for status change (always disable for the moment, will be advanced only)
Note : removed "if not gajim.awaiting_events[account].has_key(jid)" from condition for an in/out popup to be showed

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dialogs.py

    r6310 r6318  
    11151115                elif event_type == _('Groupchat Invitation'): 
    11161116                        bg_color = 'tan1' 
     1117                elif event_type == _('Contact Changed status'):                  
     1118                        bg_color = 'thistle2' 
    11171119                else: # Unknown event ! Shouldn't happen but deal with it 
    11181120                        bg_color = 'white' 
  • trunk/src/gajim.py

    r6265 r6318  
    417417                        # play sound 
    418418                        if old_show < 2 and new_show > 1: 
    419                                 if gajim.config.get_per('soundevents', 'contact_connected', 
    420                                         'enabled') and not gajim.block_signed_in_notifications[account]: 
    421                                         helpers.play_sound('contact_connected') 
    422                                 if not gajim.awaiting_events[account].has_key(jid) and \ 
    423                                         gajim.config.get('notify_on_signin') and \ 
    424                                         not gajim.block_signed_in_notifications[account]: 
    425                                         if helpers.allow_showing_notification(account): 
    426                                                 transport_name = gajim.get_transport_name_from_jid(jid) 
    427                                                 img = None 
    428                                                 if transport_name: 
    429                                                         img = os.path.join(gajim.DATA_DIR, 'iconsets', 
    430                                                                 'transports', transport_name, '48x48', 
    431                                                                 'online.png') 
    432                                                 if not img or not os.path.isfile(img): 
    433                                                         iconset = gajim.config.get('iconset') 
    434                                                         img = os.path.join(gajim.DATA_DIR, 'iconsets', 
    435                                                                         iconset, '48x48', 'online.png') 
    436                                                 path = gtkgui_helpers.get_path_to_generic_or_avatar(img, 
    437                                                         jid = jid, suffix = '_notif_size_colored.png') 
    438                                                 title = _('%(nickname)s Signed In') % \ 
    439                                                         {'nickname': gajim.get_name_from_jid(account, jid)} 
    440                                                 text = '' 
    441                                                 if status_message: 
    442                                                         text = status_message 
    443                                                 notify.notify(_('Contact Signed In'), jid, account, 
    444                                                         path_to_image = path, title = title, text = text) 
    445  
     419                                notify.notify('contact_connected', jid, account, status_message) 
    446420                                if self.remote_ctrl: 
    447421                                        self.remote_ctrl.raise_signal('ContactPresence', 
     
    449423                                 
    450424                        elif old_show > 1 and new_show < 2: 
    451                                 if gajim.config.get_per('soundevents', 'contact_disconnected', 
    452                                                 'enabled'): 
    453                                         helpers.play_sound('contact_disconnected') 
    454                                 if not gajim.awaiting_events[account].has_key(jid) and \ 
    455                                         gajim.config.get('notify_on_signout'): 
    456                                         if helpers.allow_showing_notification(account): 
    457                                                 transport_name = gajim.get_transport_name_from_jid(jid) 
    458                                                 img = None 
    459                                                 if transport_name: 
    460                                                         img = os.path.join(gajim.DATA_DIR, 'iconsets', 
    461                                                                 'transports', transport_name, '48x48', 
    462                                                                 'offline.png') 
    463                                                 if not img or not os.path.isfile(img): 
    464                                                         iconset = gajim.config.get('iconset') 
    465                                                         img = os.path.join(gajim.DATA_DIR, 'iconsets', 
    466                                                                         iconset, '48x48', 'offline.png') 
    467                                                 path = gtkgui_helpers.get_path_to_generic_or_avatar(img, 
    468                                                         jid = jid, suffix = '_notif_size_bw.png') 
    469                                                 title = _('%(nickname)s Signed Out') % \ 
    470                                                         {'nickname': gajim.get_name_from_jid(account, jid)} 
    471                                                 text = '' 
    472                                                 if status_message: 
    473                                                         text = status_message 
    474                                                 notify.notify(_('Contact Signed Out'), jid, account, 
    475                                                         path_to_image = path, title = title, text = text) 
    476  
     425                                notify.notify('contact_disconnected', jid, account, status_message) 
    477426                                if self.remote_ctrl: 
    478427                                        self.remote_ctrl.raise_signal('ContactAbsence', (account, array)) 
    479428                                # FIXME: stop non active file transfers 
     429                        elif new_show > 1: # Status change (not connected/disconnected or error (<1)) 
     430                                notify.notify('status_change', jid, account, [new_show, status_message]) 
    480431                else: 
    481432                        # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) doesn't follow the JEP 
     
    584535                                        text = _('%(nickname)s: %(message)s') % {'nickname': nick, 
    585536                                                'message': message} 
    586                                         notify.notify(_('New Private Message'), full_jid_with_resource, 
     537                                        notify.popup(_('New Private Message'), full_jid_with_resource, 
    587538                                                account, 'pm', path_to_image = path, title = title, 
    588539                                                text = text) 
     
    613564                                                {'nickname': gajim.get_name_from_jid(account, jid)} 
    614565                                path = gtkgui_helpers.get_path_to_generic_or_avatar(img) 
    615                                 notify.notify(event_type, jid_of_control, account, msg_type, 
     566                                notify.popup(event_type, jid_of_control, account, msg_type, 
    616567                                        path_to_image = path, title = title, text = text) 
    617568 
     
    969920                        path = gtkgui_helpers.get_path_to_generic_or_avatar(path) 
    970921                        event_type = _('Groupchat Invitation') 
    971                         notify.notify(event_type, jid, account, 'gc-invitation', path, 
     922                        notify.popup(event_type, jid, account, 'gc-invitation', path, 
    972923                                event_type, room_jid) 
    973924 
     
    10711022                        path = gtkgui_helpers.get_path_to_generic_or_avatar(img) 
    10721023                        event_type = _('File Transfer Error') 
    1073                         notify.notify(event_type, jid, account, 'file-send-error', path, 
     1024                        notify.popup(event_type, jid, account, 'file-send-error', path, 
    10741025                                event_type, file_props['name']) 
    10751026 
     
    10841035                        text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages) 
    10851036                        path = gtkgui_helpers.get_path_to_generic_or_avatar(img) 
    1086                         notify.notify(_('New E-mail'), jid, account, 'gmail', 
     1037                        notify.popup(_('New E-mail'), jid, account, 'gmail', 
    10871038                                path_to_image = path, title = title, text = text) 
    10881039 
     
    12001151                        path = gtkgui_helpers.get_path_to_generic_or_avatar(img) 
    12011152                        event_type = _('File Transfer Error') 
    1202                         notify.notify(event_type, jid, account, msg_type, path, 
     1153                        notify.popup(event_type, jid, account, msg_type, path, 
    12031154                                title = event_type, text = file_props['name']) 
    12041155 
     
    12231174                        path = gtkgui_helpers.get_path_to_generic_or_avatar(img) 
    12241175                        event_type = _('File Transfer Request') 
    1225                         notify.notify(event_type, jid, account, 'file-request', 
     1176                        notify.popup(event_type, jid, account, 'file-request', 
    12261177                                path_to_image = path, title = event_type, text = txt) 
    12271178 
     
    13141265                        # we want to be notified and we are online/chat or we don't mind 
    13151266                        # bugged when away/na/busy 
    1316                         notify.notify(event_type, jid, account, msg_type, path_to_image = path, 
     1267                        notify.popup(event_type, jid, account, msg_type, path_to_image = path, 
    13171268                                title = event_type, text = txt) 
    13181269 
  • trunk/src/notify.py

    r6275 r6318  
    2525from common import gajim 
    2626from common import i18n 
     27from common import helpers 
    2728i18n.init() 
    2829_ = i18n._ 
     
    3536                import dbus.service 
    3637 
    37 def notify(event_type, jid, account, msg_type = '', path_to_image = None, 
     38def notify(event, jid, account, parameters): 
     39        '''Check what type of notifications we want, depending on basic configuration 
     40        of notifications and advanced one and do these notifications''' 
     41        # First, find what notifications we want 
     42        do_popup = False 
     43        do_sound = False 
     44        if (event == 'status_change'): 
     45                new_show = parameters[0] 
     46                status_message = parameters[1] 
     47                # Default : No popup for status change 
     48        elif  (event == 'contact_connected'): 
     49                status_message = parameters 
     50                if gajim.config.get('notify_on_signin') and \ 
     51                        not gajim.block_signed_in_notifications[account]\ 
     52                        and helpers.allow_showing_notification(account): 
     53                        do_popup = True 
     54                if gajim.config.get_per('soundevents', 'contact_connected', 
     55                        'enabled') and not gajim.block_signed_in_notifications[account]: 
     56                        do_sound = True 
     57        elif (event == 'contact_disconnected'): 
     58                status_message = parameters 
     59                if gajim.config.get('notify_on_signout') \ 
     60                        and helpers.allow_showing_notification(account): 
     61                        do_popup = True 
     62                if gajim.config.get_per('soundevents', 'contact_disconnected', 
     63                        'enabled'): 
     64                        do_sound = True 
     65         
     66        # Do the wanted notifications    
     67        if (do_popup): 
     68                if (event == 'contact_connected' or event == 'contact_disconnected' or \ 
     69                        event == 'status_change'): # Common code for popup for these 3 events 
     70                        if (event == 'contact_disconnected'): 
     71                                show_image = 'offline.png' 
     72                                suffix = '_notif_size_bw.png' 
     73                        else: #Status Change or Connected 
     74                                # TODO : for status change, we don't always 'online.png', but we  
     75                                # first need 48x48 for all status 
     76                                show_image = 'online.png' 
     77                                suffix = '_notif_size_colored.png'       
     78                        transport_name = gajim.get_transport_name_from_jid(jid) 
     79                        img = None 
     80                        if transport_name: 
     81                                img = os.path.join(gajim.DATA_DIR, 'iconsets', 
     82                                        'transports', transport_name, '48x48', show_image)  
     83                        if not img or not os.path.isfile(img): 
     84                                iconset = gajim.config.get('iconset') 
     85                                img = os.path.join(gajim.DATA_DIR, 'iconsets', 
     86                                                iconset, '48x48', show_image) 
     87                        path = gtkgui_helpers.get_path_to_generic_or_avatar(img, 
     88                                jid = jid, suffix = suffix) 
     89                        if (event == 'status_change'): 
     90                                title = _('%(nick)s Changed Status') % \ 
     91                                        {'nick': gajim.get_name_from_jid(account, jid)} 
     92                                text = _('%(nick)s is now %(status)s') % \ 
     93                                        {'nick': gajim.get_name_from_jid(account, jid),\ 
     94                                        'status': helpers.get_uf_show(gajim.SHOW_LIST[new_show])} 
     95                                if status_message: 
     96                                        text =  text + " : " + status_message 
     97                                popup(_('Contact Changed status'), jid, account, 
     98                                        path_to_image = path, title = title, text = text) 
     99                        elif (event == 'contact_connected'): 
     100                                title = _('%(nickname)s Signed In') % \ 
     101                                        {'nickname': gajim.get_name_from_jid(account, jid)} 
     102                                text = '' 
     103                                if status_message: 
     104                                        text = status_message 
     105                                popup(_('Contact Signed In'), jid, account, 
     106                                        path_to_image = path, title = title, text = text) 
     107                        elif (event == 'contact_disconnected'): 
     108                                title = _('%(nickname)s Signed Out') % \ 
     109                                        {'nickname': gajim.get_name_from_jid(account, jid)} 
     110                                text = '' 
     111                                if status_message: 
     112                                        text = status_message 
     113                                popup(_('Contact Signed Out'), jid, account, 
     114                                        path_to_image = path, title = title, text = text) 
     115                        else: 
     116                                print 'Event not implemeted yet' 
     117        if (do_sound): 
     118                helpers.play_sound(event)        
     119          
     120 
     121def popup(event_type, jid, account, msg_type = '', path_to_image = None, 
    38122        title = None, text = None): 
    39123        '''Notifies a user of an event. It first tries to a valid implementation of 
     
    53137                        # This means that we sent the message incorrectly 
    54138                        gajim.log.debug(str(e)) 
    55         instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, title, text) 
     139        instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, \ 
     140                path_to_image, title, text) 
    56141        gajim.interface.roster.popup_notification_windows.append(instance) 
    57142 
     
    145230                elif event_type == _('Groupchat Invitation'): 
    146231                        ntype = 'im.invitation' 
     232                elif event_type == _('Contact Changed status'): 
     233                        ntype = 'presence.status' 
    147234                else: 
    148235                        # default failsafe values