we now show avatar instead of general contact img for online/offline

This commit is contained in:
Nikos Kouremenos 2006-01-12 22:48:49 +00:00
parent dceac477d6
commit 3c50094afa
4 changed files with 60 additions and 20 deletions

View file

@ -52,18 +52,22 @@ if os.name == 'nt':
# Documents and Settings\[User Name]\Application Data\Gajim # Documents and Settings\[User Name]\Application Data\Gajim
LOGPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Logs') # deprecated LOGPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Logs') # deprecated
VCARDPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Vcards') VCARDPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Vcards')
TMP = os.path.join(os.environ['tmp'], 'Gajim')
except KeyError: except KeyError:
# win9x, in cwd # win9x, in cwd
LOGPATH = 'Logs' # deprecated LOGPATH = 'Logs' # deprecated
VCARDPATH = 'Vcards' VCARDPATH = 'Vcards'
TMP = 'temporary files'
else: # Unices else: # Unices
DATA_DIR = '../data' DATA_DIR = '../data'
LOGPATH = os.path.expanduser('~/.gajim/logs') # deprecated LOGPATH = os.path.expanduser('~/.gajim/logs') # deprecated
VCARDPATH = os.path.expanduser('~/.gajim/vcards') VCARDPATH = os.path.expanduser('~/.gajim/vcards')
TMP = '/tmp'
try: try:
LOGPATH = LOGPATH.decode(sys.getfilesystemencoding()) LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
VCARDPATH = VCARDPATH.decode(sys.getfilesystemencoding()) VCARDPATH = VCARDPATH.decode(sys.getfilesystemencoding())
TMP = TMP.decode(sys.getfilesystemencoding())
except: except:
pass pass

View file

@ -356,10 +356,27 @@ class Interface:
# check OUR status and if we allow notifications for that status # check OUR status and if we allow notifications for that status
if gajim.config.get('autopopupaway'): # always notify if gajim.config.get('autopopupaway'): # always notify
show_notification = True show_notification = True
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3):
# we're online or chat
show_notification = True show_notification = True
if show_notification: if show_notification:
notify.notify(_('Contact Signed In'), jid, account) avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(
jid)
if avatar_pixbuf is None:
path_to_file = None
else:
avatar_pixbuf = gtkgui_helpers.get_scaled_pixbuf(
avatar_pixbuf, 'roster')
path_to_file = os.path.join(gajim.TMP, jid + '.png')
if not os.path.exists(path_to_file):
try:
avatar_pixbuf.save(path_to_file, 'png')
except gobject.GError, e:
path_to_file = None
notify.notify(_('Contact Signed In'), jid, account,
path_to_image = path_to_file)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('ContactPresence', self.remote_ctrl.raise_signal('ContactPresence',
(account, array)) (account, array))
@ -378,7 +395,24 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True show_notification = True
if show_notification: if show_notification:
notify.notify(_('Contact Signed Out'), jid, account) avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(
jid)
if avatar_pixbuf is None:
path_to_file = None
else:
avatar_pixbuf = gtkgui_helpers.get_scaled_pixbuf(
avatar_pixbuf, 'roster')
path_to_file = os.path.join(gajim.TMP, jid + '_BW.png')
if not os.path.exists(path_to_file):
try:
avatar_pixbuf = gtkgui_helpers.make_pixbuf_grayscale(
avatar_pixbuf)
avatar_pixbuf.save(path_to_file, 'png')
except gobject.GError, e:
path_to_file = None
notify.notify(_('Contact Signed Out'), jid, account,
path_to_image = path_to_file)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('ContactAbsence', (account, array)) self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
# FIXME: stop non active file transfers # FIXME: stop non active file transfers

View file

@ -464,3 +464,8 @@ def make_color_string(color):
'''create #aabbcc color string from gtk color''' '''create #aabbcc color string from gtk color'''
return '#' + hex(color.red)[-2:] + hex(color.green)[-2:] + \ return '#' + hex(color.red)[-2:] + hex(color.green)[-2:] + \
hex(color.blue)[-2:] hex(color.blue)[-2:]
def make_pixbuf_grayscale(pixbuf):
pixbuf2 = pixbuf.copy()
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
return pixbuf2

View file

@ -47,13 +47,15 @@ if dbus_support.supported:
import dbus.glib import dbus.glib
import dbus.service import dbus.service
def notify(event_type, jid, account, msg_type = '', file_props = None): def notify(event_type, jid, account, msg_type = '', file_props = None,
path_to_image = None):
'''Notifies a user of an event. It first tries to a valid implementation of '''Notifies a user of an event. It first tries to a valid implementation of
the Desktop Notification Specification. If that fails, then we fall back to the Desktop Notification Specification. If that fails, then we fall back to
the older style PopupNotificationWindow method.''' the older style PopupNotificationWindow method.'''
if gajim.config.get('use_notif_daemon') and dbus_support.supported: if gajim.config.get('use_notif_daemon') and dbus_support.supported:
try: try:
DesktopNotification(event_type, jid, account, msg_type, file_props) DesktopNotification(event_type, jid, account, msg_type, file_props,
path_to_image)
return return
except dbus.dbus_bindings.DBusException, e: except dbus.dbus_bindings.DBusException, e:
# Connection to D-Bus failed, try popup # Connection to D-Bus failed, try popup
@ -99,7 +101,8 @@ notification_response_manager = NotificationResponseManager()
class DesktopNotification: class DesktopNotification:
'''A DesktopNotification that interfaces with DBus via the Desktop '''A DesktopNotification that interfaces with DBus via the Desktop
Notification specification''' Notification specification'''
def __init__(self, event_type, jid, account, msg_type = '', file_props = None): def __init__(self, event_type, jid, account, msg_type = '',
file_props = None, path_to_image = None):
self.account = account self.account = account
self.jid = jid self.jid = jid
self.msg_type = msg_type self.msg_type = msg_type
@ -118,24 +121,18 @@ class DesktopNotification:
prefix = transport_name prefix = transport_name
else: else:
prefix = 'jabber' prefix = 'jabber'
'''
if transport_name == 'aim':
prefix = 'aim'
elif transport_name == 'icq':
prefix = 'icq'
elif transport_name == 'msn':
prefix = 'msn'
elif transport_name == 'yahoo':
prefix = 'yahoo'
else:
prefix = 'jabber'
'''
if event_type == _('Contact Signed In'): if event_type == _('Contact Signed In'):
img = prefix + '_online.png' if path_to_image is None:
img = prefix + '_online.png'
else:
img = path_to_image
ntype = 'presence.online' ntype = 'presence.online'
elif event_type == _('Contact Signed Out'): elif event_type == _('Contact Signed Out'):
img = prefix + '_offline.png' if path_to_image is None:
img = prefix + '_offline.png'
else:
img = path_to_image
ntype = 'presence.offline' ntype = 'presence.offline'
elif event_type in (_('New Message'), _('New Single Message'), elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')): _('New Private Message')):