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
LOGPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Logs') # deprecated
VCARDPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Vcards')
TMP = os.path.join(os.environ['tmp'], 'Gajim')
except KeyError:
# win9x, in cwd
LOGPATH = 'Logs' # deprecated
VCARDPATH = 'Vcards'
TMP = 'temporary files'
else: # Unices
DATA_DIR = '../data'
LOGPATH = os.path.expanduser('~/.gajim/logs') # deprecated
VCARDPATH = os.path.expanduser('~/.gajim/vcards')
TMP = '/tmp'
try:
LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
VCARDPATH = VCARDPATH.decode(sys.getfilesystemencoding())
TMP = TMP.decode(sys.getfilesystemencoding())
except:
pass

View File

@ -356,10 +356,27 @@ class Interface:
# check OUR status and if we allow notifications for that status
if gajim.config.get('autopopupaway'): # always notify
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
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:
self.remote_ctrl.raise_signal('ContactPresence',
(account, array))
@ -378,7 +395,24 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True
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:
self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
# FIXME: stop non active file transfers

View File

@ -464,3 +464,8 @@ def make_color_string(color):
'''create #aabbcc color string from gtk color'''
return '#' + hex(color.red)[-2:] + hex(color.green)[-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.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
the Desktop Notification Specification. If that fails, then we fall back to
the older style PopupNotificationWindow method.'''
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
try:
DesktopNotification(event_type, jid, account, msg_type, file_props)
DesktopNotification(event_type, jid, account, msg_type, file_props,
path_to_image)
return
except dbus.dbus_bindings.DBusException, e:
# Connection to D-Bus failed, try popup
@ -99,7 +101,8 @@ notification_response_manager = NotificationResponseManager()
class DesktopNotification:
'''A DesktopNotification that interfaces with DBus via the Desktop
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.jid = jid
self.msg_type = msg_type
@ -118,24 +121,18 @@ class DesktopNotification:
prefix = transport_name
else:
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'):
img = prefix + '_online.png'
if path_to_image is None:
img = prefix + '_online.png'
else:
img = path_to_image
ntype = 'presence.online'
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'
elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')):