* src/GrampsMime.py: detect directory type
* src/ImageSelect.py: don't allow directory types to be added * src/MediaView.py: don't allow directory types to be added svn: r5923
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
2006-02-11 Don Allingham <don@gramps-project.org>
|
||||
* src/GrampsMime.py: detect directory type
|
||||
* src/ImageSelect.py: don't allow directory types to be added
|
||||
* src/MediaView.py: don't allow directory types to be added
|
||||
|
||||
2006-02-11 Alex Roitman <shura@gramps-project.org>
|
||||
* src/DbPrompter.py (open_native): Use empty GRDB when opening fails.
|
||||
|
||||
|
@ -59,3 +59,16 @@ def mime_type_is_defined(type):
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def base_type(val):
|
||||
return val.split('/')[0]
|
||||
|
||||
def is_image_type(val):
|
||||
return base_type(val) == "image"
|
||||
|
||||
def is_directory(val):
|
||||
return base_type(val) == "x-directory"
|
||||
_invalid_mime_types = ('x-directory','x-special')
|
||||
|
||||
def is_valid_type(val):
|
||||
return base_type(val) not in _invalid_mime_types
|
||||
|
@ -169,6 +169,12 @@ class ImageSelect:
|
||||
filename = Utils.find_file( filename)
|
||||
if filename:
|
||||
mtype = GrampsMime.get_type(filename)
|
||||
if not GrampsMime.is_valid_type(mtype):
|
||||
ErrorDialog(_('Invalid file type'),
|
||||
_('An object of type %s cannot be added '
|
||||
'to a gallery') % mtype)
|
||||
return
|
||||
|
||||
if mtype and mtype.startswith("image"):
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
self.image.set_from_pixbuf(image)
|
||||
@ -209,12 +215,18 @@ class ImageSelect:
|
||||
self.add_thumbnail(oref)
|
||||
else:
|
||||
mtype = GrampsMime.get_type(filename)
|
||||
mobj = RelLib.MediaObject()
|
||||
if description == "":
|
||||
description = os.path.basename(filename)
|
||||
mobj.set_description(description)
|
||||
mobj.set_mime_type(mtype)
|
||||
mobj.set_path(filename)
|
||||
if GrampsMime.is_valid_type(mtype):
|
||||
mobj = RelLib.MediaObject()
|
||||
if description == "":
|
||||
description = os.path.basename(filename)
|
||||
mobj.set_description(description)
|
||||
mobj.set_mime_type(mtype)
|
||||
mobj.set_path(filename)
|
||||
else:
|
||||
ErrorDialog(_('Invalid file type'),
|
||||
_('An object of type %s cannot be added '
|
||||
'to a gallery') % mtype)
|
||||
return
|
||||
else:
|
||||
mobj = RelLib.MediaObject()
|
||||
mobj.set_description(description)
|
||||
@ -493,6 +505,8 @@ class Gallery(ImageSelect):
|
||||
if protocol == "file":
|
||||
name = Utils.fix_encoding(mfile)
|
||||
mime = GrampsMime.get_type(name)
|
||||
if not GrampsMime.is_valid_type(mime):
|
||||
return
|
||||
photo = RelLib.MediaObject()
|
||||
photo.set_path(name)
|
||||
photo.set_mime_type(mime)
|
||||
|
@ -403,6 +403,11 @@ class MediaView:
|
||||
protocol,site,name, j,k,l = urlparse.urlparse(d)
|
||||
if protocol == "file":
|
||||
mime = GrampsMime.get_type(name)
|
||||
if not GrampsMime.is_valid_type(mime):
|
||||
ErrorDialog(_('Invalid file type'),
|
||||
_('An object of type %s cannot be added '
|
||||
'to a gallery') % mime)
|
||||
return
|
||||
photo = RelLib.MediaObject()
|
||||
photo.set_path(name)
|
||||
photo.set_mime_type(mime)
|
||||
@ -426,6 +431,11 @@ class MediaView:
|
||||
ErrorDialog(_('Image import failed'),str(msg))
|
||||
return
|
||||
mime = GrampsMime.get_type(tfile)
|
||||
if not GrampsMime.is_valid_type(mime):
|
||||
ErrorDialog(_('Invalid file type'),
|
||||
_('An object of type %s cannot be added '
|
||||
'to a gallery') % mtype)
|
||||
return
|
||||
photo = RelLib.MediaObject()
|
||||
photo.set_mime_type(mime)
|
||||
photo.set_description(d)
|
||||
|
Reference in New Issue
Block a user