Choosing an avatar : Catch also invalid format errors for files < 16kb
This commit is contained in:
parent
c4d10a780e
commit
2052410b3c
|
@ -132,7 +132,7 @@ class ProfileWindow:
|
||||||
try:
|
try:
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
||||||
# get the image at 'notification size'
|
# get the image at 'notification size'
|
||||||
# and use that user did not specify in ACE crazy size
|
# and hope that user did not specify in ACE crazy size
|
||||||
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf,
|
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf,
|
||||||
'tooltip')
|
'tooltip')
|
||||||
except gobject.GError, msg: # unknown format
|
except gobject.GError, msg: # unknown format
|
||||||
|
@ -149,13 +149,17 @@ class ProfileWindow:
|
||||||
'avatar_scaled.png')
|
'avatar_scaled.png')
|
||||||
scaled_pixbuf.save(path_to_file, 'png')
|
scaled_pixbuf.save(path_to_file, 'png')
|
||||||
must_delete = True
|
must_delete = True
|
||||||
self.dialog.destroy()
|
|
||||||
|
|
||||||
fd = open(path_to_file, 'rb')
|
fd = open(path_to_file, 'rb')
|
||||||
data = fd.read()
|
data = fd.read()
|
||||||
pixbuf = gtkgui_helpers.get_pixbuf_from_data(data)
|
pixbuf = gtkgui_helpers.get_pixbuf_from_data(data)
|
||||||
# rescale it
|
try:
|
||||||
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'vcard')
|
# rescale it
|
||||||
|
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'vcard')
|
||||||
|
except AttributeError: # unknown format
|
||||||
|
dialogs.ErrorDialog(_('Could not load image'), msg)
|
||||||
|
return
|
||||||
|
self.dialog.destroy()
|
||||||
button = self.xml.get_widget('PHOTO_button')
|
button = self.xml.get_widget('PHOTO_button')
|
||||||
image = button.get_image()
|
image = button.get_image()
|
||||||
image.set_from_pixbuf(pixbuf)
|
image.set_from_pixbuf(pixbuf)
|
||||||
|
|
17
src/vcard.py
17
src/vcard.py
|
@ -139,16 +139,17 @@ class VcardWindow:
|
||||||
if invalid_file:
|
if invalid_file:
|
||||||
dialogs.ErrorDialog(_('Could not load image'), msg)
|
dialogs.ErrorDialog(_('Could not load image'), msg)
|
||||||
return
|
return
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
try:
|
||||||
if filesize > 16384: # 16 kb
|
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
||||||
try:
|
if filesize > 16384: # 16 kb
|
||||||
# get the image at 'notification size'
|
# get the image at 'notification size'
|
||||||
# and use that user did not specify in ACE crazy size
|
# and hope that user did not specify in ACE crazy size
|
||||||
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'tooltip')
|
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'tooltip')
|
||||||
except gobject.GError, msg: # unknown format
|
except gobject.GError, msg: # unknown format
|
||||||
# msg should be string, not object instance
|
# msg should be string, not object instance
|
||||||
msg = str(msg)
|
msg = str(msg)
|
||||||
invalid_file = True
|
dialogs.ErrorDialog(_('Could not load image'), msg)
|
||||||
|
return
|
||||||
puny_jid = helpers.sanitize_filename(self.contact.jid)
|
puny_jid = helpers.sanitize_filename(self.contact.jid)
|
||||||
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + '_local.png'
|
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + '_local.png'
|
||||||
pixbuf.save(path_to_file, 'png')
|
pixbuf.save(path_to_file, 'png')
|
||||||
|
|
Loading…
Reference in New Issue