Author: steve-e
Date: 2007-08-26 12:23:39 +0200 (Sun, 26 Aug 2007)
New Revision: 8570
Modified:
trunk/src/gajim.py
trunk/src/gtkgui_helpers.py
trunk/src/roster_window.py
Log:
Generalize save_avatar_files() and generate notif and bw version for local avatars.
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2007-08-26 07:11:00 UTC (rev 8569)
+++ trunk/src/gajim.py 2007-08-26 10:23:39 UTC (rev 8570)
@@ -1463,50 +1463,63 @@
if self.remote_ctrl:
self.remote_ctrl.raise_signal('NewGmail', (account, array))
- def save_avatar_files(self, jid, photo_decoded, puny_nick = None):
- '''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
+ def save_avatar_files(self, jid, photo, puny_nick = None, local = False):
+ '''Saves an avatar to a separate file, and generate files for dbus notifications. An avatar can be given as a pixmap directly or as an decoded image.'''
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
if puny_nick:
path_to_file = os.path.join(path_to_file, puny_nick)
# remove old avatars
for typ in ('jpeg', 'png'):
- path_to_original_file = path_to_file + '.' + typ
+ if local:
+ path_to_original_file = path_to_file + '_local'+ '.' + typ
+ else:
+ path_to_original_file = path_to_file + '.' + typ
if os.path.isfile(path_to_original_file):
os.remove(path_to_original_file)
- pixbuf, typ = gtkgui_helpers.get_pixbuf_from_data(photo_decoded,
- want_type = True)
- if pixbuf is None:
- return
- if typ not in ('jpeg', 'png'):
- gajim.log.debug('gtkpixbuf cannot save other than jpeg and png formats. saving %s\'avatar as png file (originaly %s)' % (jid, typ))
- typ = 'png'
- path_to_original_file = path_to_file + '.' + typ
+ if local and photo:
+ pixbuf = photo
+ type = 'png'
+ extension = '_local.png' # save local avatars as png file
+ else:
+ pixbuf, typ = gtkgui_helpers.get_pixbuf_from_data(photo, want_type = True)
+ extension = '.' + typ
+ if pixbuf is None:
+ return
+ if typ not in ('jpeg', 'png'):
+ gajim.log.debug('gtkpixbuf cannot save other than jpeg and png formats. saving %s\'avatar as png file (originaly %s)' % (jid, typ))
+ typ = 'png'
+ extension = '.png'
+ path_to_original_file = path_to_file + extension
pixbuf.save(path_to_original_file, typ)
# Generate and save the resized, color avatar
- pixbuf = gtkgui_helpers.get_scaled_pixbuf(
- gtkgui_helpers.get_pixbuf_from_data(photo_decoded), 'notification')
+ pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'notification')
if pixbuf:
- path_to_normal_file = path_to_file + '_notif_size_colored.png'
+ path_to_normal_file = path_to_file + '_notif_size_colored' + extension
pixbuf.save(path_to_normal_file, 'png')
# Generate and save the resized, black and white avatar
bwbuf = gtkgui_helpers.get_scaled_pixbuf(
gtkgui_helpers.make_pixbuf_grayscale(pixbuf), 'notification')
if bwbuf:
- path_to_bw_file = path_to_file + '_notif_size_bw.png'
+ path_to_bw_file = path_to_file + '_notif_size_bw' + extension
bwbuf.save(path_to_bw_file, 'png')
- def remove_avatar_files(self, jid, puny_nick = None):
+ def remove_avatar_files(self, jid, puny_nick = None, local = False):
'''remove avatar files of a jid'''
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
if puny_nick:
path_to_file = os.path.join(path_to_file, puny_nick)
- for ext in ('.jpeg', '.png', '_notif_size_colored.png',
- '_notif_size_bw.png'):
+ for ext in ('.jpeg', '.png'):
+ if local:
+ ext = '_local' + ext
path_to_original_file = path_to_file + ext
- if os.path.isfile(path_to_original_file):
- os.remove(path_to_original_file)
+ if os.path.isfile(path_to_file + ext):
+ os.remove(path_to_file + ext)
+ if os.path.isfile(path_to_file + '_notif_size_colored' + ext):
+ os.remove(path_to_file + '_notif_size_colored' + ext)
+ if os.path.isfile(path_to_file + '_notif_size_bw' + ext):
+ os.remove(path_to_file + '_notif_size_bw' + ext)
# list the retained secrets we have for a local account and a remote jid
def list_secrets(self, account, jid):
Modified: trunk/src/gtkgui_helpers.py
===================================================================
--- trunk/src/gtkgui_helpers.py 2007-08-26 07:11:00 UTC (rev 8569)
+++ trunk/src/gtkgui_helpers.py 2007-08-26 10:23:39 UTC (rev 8570)
@@ -605,7 +605,7 @@
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + suffix
filepath, extension = os.path.splitext(path_to_file)
path_to_local_file = filepath + '_local' + extension
- if os.path.exists(path_to_local_file):
+ if os.path.exists(path_to_local_file):
return path_to_local_file
if os.path.exists(path_to_file):
return path_to_file
Modified: trunk/src/roster_window.py
===================================================================
--- trunk/src/roster_window.py 2007-08-26 07:11:00 UTC (rev 8569)
+++ trunk/src/roster_window.py 2007-08-26 10:23:39 UTC (rev 8570)
@@ -1888,7 +1888,7 @@
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
if filesize > 16384: # 16 kb
- # get the image at 'notification size'
+ # get the image at 'tooltip size'
# and hope that user did not specify in ACE crazy size
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'tooltip')
except gobject.GError, msg: # unknown format
@@ -1896,21 +1896,14 @@
msg = str(msg)
dialogs.ErrorDialog(_('Could not load image'), msg)
return
- puny_jid = helpers.sanitize_filename(contact.jid)
- path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + '_local.png'
- pixbuf.save(path_to_file, 'png')
+ gajim.interface.save_avatar_files(contact.jid, pixbuf, local = True)
dlg.destroy()
self.update_avatar_in_gui(contact.jid, account)
def on_clear(widget):
dlg.destroy()
# Delete file:
- puny_jid = helpers.sanitize_filename(contact.jid)
- path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + '_local.png'
- try:
- os.remove(path_to_file)
- except OSError:
- gajim.log.debug('Cannot remove %s' % path_to_file)
+ gajim.interface.remove_avatar_files(contact.jid, local = True)
self.update_avatar_in_gui(contact.jid, account)
dlg = dialogs.AvatarChooserDialog(on_response_ok = on_ok,