[knuckles] improved popup notification to show avatar
This commit is contained in:
parent
7024ada55c
commit
bab21aaf56
|
@ -74,6 +74,7 @@ def create_log_db():
|
|||
def check_and_possibly_create_paths():
|
||||
LOG_DB_PATH = logger.LOG_DB_PATH
|
||||
VCARDPATH = gajim.VCARDPATH
|
||||
AVATARPATH = gajim.AVATARPATH
|
||||
dot_gajim = os.path.dirname(VCARDPATH)
|
||||
if os.path.isfile(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 _('Gajim will now 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):
|
||||
create_log_db()
|
||||
|
@ -107,5 +116,5 @@ def check_and_possibly_create_paths():
|
|||
print _('creating %s directory') % VCARDPATH
|
||||
os.mkdir(VCARDPATH, 0700)
|
||||
if not os.path.isfile(LOG_DB_PATH):
|
||||
create_log_db()
|
||||
create_log_db()
|
||||
gajim.logger.init_vars()
|
||||
|
|
|
@ -168,6 +168,8 @@ class Config:
|
|||
'chat_avatar_height': [opt_int, 52],
|
||||
'roster_avatar_width': [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.')],
|
||||
'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.')],
|
||||
|
|
|
@ -288,6 +288,7 @@ class Connection:
|
|||
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
||||
card = vc.getChildren()[0]
|
||||
vcard = self.node_to_dict(card)
|
||||
photo_decoded = None
|
||||
if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \
|
||||
vcard['PHOTO'].has_key('BINVAL'):
|
||||
photo = vcard['PHOTO']['BINVAL']
|
||||
|
@ -309,6 +310,9 @@ class Connection:
|
|||
fil = open(path_to_file, 'w')
|
||||
fil.write(str(card))
|
||||
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['resource'] = resource
|
||||
|
|
|
@ -53,21 +53,25 @@ if os.name == 'nt':
|
|||
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')
|
||||
AVATARPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Avatars')
|
||||
except KeyError:
|
||||
# win9x, in cwd
|
||||
LOGPATH = 'Logs' # deprecated
|
||||
VCARDPATH = 'Vcards'
|
||||
TMP = 'temporary files'
|
||||
AVATARPATH = 'Avatars'
|
||||
else: # Unices
|
||||
DATA_DIR = '../data'
|
||||
LOGPATH = os.path.expanduser('~/.gajim/logs') # deprecated
|
||||
VCARDPATH = os.path.expanduser('~/.gajim/vcards')
|
||||
TMP = '/tmp'
|
||||
AVATARPATH = os.path.expanduser('~/.gajim/avatars')
|
||||
|
||||
try:
|
||||
LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
|
||||
VCARDPATH = VCARDPATH.decode(sys.getfilesystemencoding())
|
||||
TMP = TMP.decode(sys.getfilesystemencoding())
|
||||
AVATARPATH = AVATARPATH.decode(sys.getfilesystemencoding())
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
57
src/gajim.py
57
src/gajim.py
|
@ -360,22 +360,8 @@ class Interface:
|
|||
# we're online or chat
|
||||
show_notification = True
|
||||
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,
|
||||
path_to_image = path_to_file)
|
||||
path_to_image = None)
|
||||
|
||||
if self.remote_ctrl:
|
||||
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
|
||||
show_notification = True
|
||||
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,
|
||||
path_to_image = path_to_file)
|
||||
path_to_image = None)
|
||||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
|
||||
# FIXME: stop non active file transfers
|
||||
|
@ -863,11 +833,32 @@ class Interface:
|
|||
if gajim.show_notification(account):
|
||||
notify.notify(_('File Transfer Error'),
|
||||
jid, account, 'file-send-error', file_props)
|
||||
|
||||
|
||||
def handle_event_gmail_notify(self, account, jid):
|
||||
if gajim.config.get('notify_on_new_gmail_email'):
|
||||
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):
|
||||
'''add an event to the awaiting_events var'''
|
||||
# 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):
|
||||
'''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
|
||||
# (keep aspect ratio)
|
||||
|
|
|
@ -123,16 +123,18 @@ class DesktopNotification:
|
|||
prefix = 'jabber'
|
||||
|
||||
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'
|
||||
else:
|
||||
img = path_to_image
|
||||
img = path_to_file
|
||||
ntype = 'presence.online'
|
||||
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'
|
||||
else:
|
||||
img = path_to_image
|
||||
img = path_to_file
|
||||
ntype = 'presence.offline'
|
||||
elif event_type in (_('New Message'), _('New Single Message'),
|
||||
_('New Private Message')):
|
||||
|
|
Loading…
Reference in New Issue