[knuckles] improved popup notification to show avatar
This commit is contained in:
parent
7024ada55c
commit
bab21aaf56
7 changed files with 51 additions and 39 deletions
|
@ -74,6 +74,7 @@ def create_log_db():
|
||||||
def check_and_possibly_create_paths():
|
def check_and_possibly_create_paths():
|
||||||
LOG_DB_PATH = logger.LOG_DB_PATH
|
LOG_DB_PATH = logger.LOG_DB_PATH
|
||||||
VCARDPATH = gajim.VCARDPATH
|
VCARDPATH = gajim.VCARDPATH
|
||||||
|
AVATARPATH = gajim.AVATARPATH
|
||||||
dot_gajim = os.path.dirname(VCARDPATH)
|
dot_gajim = os.path.dirname(VCARDPATH)
|
||||||
if os.path.isfile(dot_gajim):
|
if os.path.isfile(dot_gajim):
|
||||||
print _('%s is file but it should be a directory') % dot_gajim
|
print _('%s is file but it should be a directory') % dot_gajim
|
||||||
|
@ -91,6 +92,14 @@ def check_and_possibly_create_paths():
|
||||||
print _('%s is file but it should be a directory') % VCARDPATH
|
print _('%s is file but it should be a directory') % VCARDPATH
|
||||||
print _('Gajim will now exit')
|
print _('Gajim will now exit')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
if not os.path.exists(AVATARPATH):
|
||||||
|
print _('creating %s directory') % AVATARPATH
|
||||||
|
os.mkdir(AVATARPATH, 0700)
|
||||||
|
elif os.path.isfile(AVATARPATH):
|
||||||
|
print _('%s is file but it should be a directory') % AVATARPATH
|
||||||
|
print _('Gajim will now exit')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.exists(LOG_DB_PATH):
|
if not os.path.exists(LOG_DB_PATH):
|
||||||
create_log_db()
|
create_log_db()
|
||||||
|
@ -107,5 +116,5 @@ def check_and_possibly_create_paths():
|
||||||
print _('creating %s directory') % VCARDPATH
|
print _('creating %s directory') % VCARDPATH
|
||||||
os.mkdir(VCARDPATH, 0700)
|
os.mkdir(VCARDPATH, 0700)
|
||||||
if not os.path.isfile(LOG_DB_PATH):
|
if not os.path.isfile(LOG_DB_PATH):
|
||||||
create_log_db()
|
create_log_db()
|
||||||
gajim.logger.init_vars()
|
gajim.logger.init_vars()
|
||||||
|
|
|
@ -168,6 +168,8 @@ class Config:
|
||||||
'chat_avatar_height': [opt_int, 52],
|
'chat_avatar_height': [opt_int, 52],
|
||||||
'roster_avatar_width': [opt_int, 32],
|
'roster_avatar_width': [opt_int, 32],
|
||||||
'roster_avatar_height': [opt_int, 32],
|
'roster_avatar_height': [opt_int, 32],
|
||||||
|
'notification_avatar_width': [opt_int, 48],
|
||||||
|
'notification_avatar_height': [opt_int, 48],
|
||||||
'muc_highlight_words': [opt_str, '', _('A semicolon-separated list of words that will be highlighted in multi-user chat.')],
|
'muc_highlight_words': [opt_str, '', _('A semicolon-separated list of words that will be highlighted in multi-user chat.')],
|
||||||
'quit_on_roster_x_button': [opt_bool, False, _('If True, quits Gajim when X button of Window Manager is clicked. This setting is taken into account only if trayicon is used.')],
|
'quit_on_roster_x_button': [opt_bool, False, _('If True, quits Gajim when X button of Window Manager is clicked. This setting is taken into account only if trayicon is used.')],
|
||||||
'set_xmpp://_handler_everytime': [opt_bool, False, _('If True, Gajim registers for xmpp:// on each startup.')],
|
'set_xmpp://_handler_everytime': [opt_bool, False, _('If True, Gajim registers for xmpp:// on each startup.')],
|
||||||
|
|
|
@ -288,6 +288,7 @@ class Connection:
|
||||||
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
||||||
card = vc.getChildren()[0]
|
card = vc.getChildren()[0]
|
||||||
vcard = self.node_to_dict(card)
|
vcard = self.node_to_dict(card)
|
||||||
|
photo_decoded = None
|
||||||
if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \
|
if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \
|
||||||
vcard['PHOTO'].has_key('BINVAL'):
|
vcard['PHOTO'].has_key('BINVAL'):
|
||||||
photo = vcard['PHOTO']['BINVAL']
|
photo = vcard['PHOTO']['BINVAL']
|
||||||
|
@ -309,6 +310,9 @@ class Connection:
|
||||||
fil = open(path_to_file, 'w')
|
fil = open(path_to_file, 'w')
|
||||||
fil.write(str(card))
|
fil.write(str(card))
|
||||||
fil.close()
|
fil.close()
|
||||||
|
# Save the decoded avatar to a separate file too, and generate files for dbus notifications
|
||||||
|
if photo_decoded:
|
||||||
|
gajim.interface.save_avatar_files(frm, photo_decoded)
|
||||||
|
|
||||||
vcard['jid'] = frm
|
vcard['jid'] = frm
|
||||||
vcard['resource'] = resource
|
vcard['resource'] = resource
|
||||||
|
|
|
@ -53,21 +53,25 @@ if os.name == 'nt':
|
||||||
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')
|
TMP = os.path.join(os.environ['tmp'], 'Gajim')
|
||||||
|
AVATARPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Avatars')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# win9x, in cwd
|
# win9x, in cwd
|
||||||
LOGPATH = 'Logs' # deprecated
|
LOGPATH = 'Logs' # deprecated
|
||||||
VCARDPATH = 'Vcards'
|
VCARDPATH = 'Vcards'
|
||||||
TMP = 'temporary files'
|
TMP = 'temporary files'
|
||||||
|
AVATARPATH = 'Avatars'
|
||||||
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'
|
TMP = '/tmp'
|
||||||
|
AVATARPATH = os.path.expanduser('~/.gajim/avatars')
|
||||||
|
|
||||||
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())
|
TMP = TMP.decode(sys.getfilesystemencoding())
|
||||||
|
AVATARPATH = AVATARPATH.decode(sys.getfilesystemencoding())
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
57
src/gajim.py
57
src/gajim.py
|
@ -360,22 +360,8 @@ class Interface:
|
||||||
# we're online or chat
|
# we're online or chat
|
||||||
show_notification = True
|
show_notification = True
|
||||||
if show_notification:
|
if show_notification:
|
||||||
avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(
|
|
||||||
jid)
|
|
||||||
if avatar_pixbuf in (None, 'ask'):
|
|
||||||
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,
|
notify.notify(_('Contact Signed In'), jid, account,
|
||||||
path_to_image = path_to_file)
|
path_to_image = None)
|
||||||
|
|
||||||
if self.remote_ctrl:
|
if self.remote_ctrl:
|
||||||
self.remote_ctrl.raise_signal('ContactPresence',
|
self.remote_ctrl.raise_signal('ContactPresence',
|
||||||
|
@ -395,24 +381,8 @@ 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:
|
||||||
avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(
|
|
||||||
jid)
|
|
||||||
if avatar_pixbuf in (None, 'ask'):
|
|
||||||
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,
|
notify.notify(_('Contact Signed Out'), jid, account,
|
||||||
path_to_image = path_to_file)
|
path_to_image = None)
|
||||||
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
|
||||||
|
@ -863,11 +833,32 @@ class Interface:
|
||||||
if gajim.show_notification(account):
|
if gajim.show_notification(account):
|
||||||
notify.notify(_('File Transfer Error'),
|
notify.notify(_('File Transfer Error'),
|
||||||
jid, account, 'file-send-error', file_props)
|
jid, account, 'file-send-error', file_props)
|
||||||
|
|
||||||
def handle_event_gmail_notify(self, account, jid):
|
def handle_event_gmail_notify(self, account, jid):
|
||||||
if gajim.config.get('notify_on_new_gmail_email'):
|
if gajim.config.get('notify_on_new_gmail_email'):
|
||||||
notify.notify(_('New E-mail'), jid, account)
|
notify.notify(_('New E-mail'), jid, account)
|
||||||
|
|
||||||
|
def save_avatar_files(self, jid, photo_decoded):
|
||||||
|
'''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
|
||||||
|
path_to_file = os.path.join(gajim.AVATARPATH, jid)
|
||||||
|
pixbuf, typ = gtkgui_helpers.get_pixbuf_from_data(photo_decoded,
|
||||||
|
want_type = True)
|
||||||
|
if typ in ('jpeg', 'png'):
|
||||||
|
path_to_original_file = path_to_file + '.' + typ
|
||||||
|
pixbuf.save(path_to_original_file, typ)
|
||||||
|
else:
|
||||||
|
gajim.log.debug('gtkpixbuf cannot save other than jpeg and png formats. skipping avatar of %s') % jid
|
||||||
|
# Generate and save the resized, color avatar
|
||||||
|
path_to_normal_file = path_to_file + '_notf_size_colored.png'
|
||||||
|
pixbuf = gtkgui_helpers.get_scaled_pixbuf(
|
||||||
|
gtkgui_helpers.get_pixbuf_from_data(photo_decoded), 'notification')
|
||||||
|
pixbuf.save(path_to_normal_file, 'png')
|
||||||
|
# Generate and save the resized, black and white avatar
|
||||||
|
path_to_bw_file = path_to_file + '_notf_size_bw.png'
|
||||||
|
bwbuf = gtkgui_helpers.get_scaled_pixbuf(
|
||||||
|
gtkgui_helpers.make_pixbuf_grayscale(pixbuf), 'notification')
|
||||||
|
bwbuf.save(path_to_bw_file, 'png')
|
||||||
|
|
||||||
def add_event(self, account, jid, typ, args):
|
def add_event(self, account, jid, typ, args):
|
||||||
'''add an event to the awaiting_events var'''
|
'''add an event to the awaiting_events var'''
|
||||||
# We add it to the awaiting_events queue
|
# We add it to the awaiting_events queue
|
||||||
|
|
|
@ -413,7 +413,7 @@ def _get_fade_color(treeview, selected, focused):
|
||||||
|
|
||||||
def get_scaled_pixbuf(pixbuf, type):
|
def get_scaled_pixbuf(pixbuf, type):
|
||||||
'''returns scaled pixbuf, keeping ratio etc
|
'''returns scaled pixbuf, keeping ratio etc
|
||||||
type is either "chat" or "roster"'''
|
type is either "chat" or "roster" or "notification"'''
|
||||||
|
|
||||||
# resize to a width / height for the avatar not to have distortion
|
# resize to a width / height for the avatar not to have distortion
|
||||||
# (keep aspect ratio)
|
# (keep aspect ratio)
|
||||||
|
|
|
@ -123,16 +123,18 @@ class DesktopNotification:
|
||||||
prefix = 'jabber'
|
prefix = 'jabber'
|
||||||
|
|
||||||
if event_type == _('Contact Signed In'):
|
if event_type == _('Contact Signed In'):
|
||||||
if path_to_image is None:
|
path_to_file = os.path.join(gajim.AVATARPATH, jid) + '_notf_size_colored.png'
|
||||||
|
if not os.path.exists(path_to_file):
|
||||||
img = prefix + '_online.png'
|
img = prefix + '_online.png'
|
||||||
else:
|
else:
|
||||||
img = path_to_image
|
img = path_to_file
|
||||||
ntype = 'presence.online'
|
ntype = 'presence.online'
|
||||||
elif event_type == _('Contact Signed Out'):
|
elif event_type == _('Contact Signed Out'):
|
||||||
if path_to_image is None:
|
path_to_file = os.path.join(gajim.AVATARPATH, jid) + '_notf_size_bw.png'
|
||||||
|
if not os.path.exists(path_to_file):
|
||||||
img = prefix + '_offline.png'
|
img = prefix + '_offline.png'
|
||||||
else:
|
else:
|
||||||
img = path_to_image
|
img = path_to_file
|
||||||
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')):
|
||||||
|
|
Loading…
Add table
Reference in a new issue