* src/DisplayModels.py: try to handle encoding errors
* src/ImageSelect.py: call fix_encoding to handle path names * src/Utils.py: provide a routine to attempt to fix encoding of str values * src/plugins/Check.py: repair bad filenames svn: r5403
This commit is contained in:
parent
9f92d0ddbd
commit
56f780b876
@ -1,3 +1,10 @@
|
||||
2005-11-16 Don Allingham <don@gramps-project.org>
|
||||
* src/DisplayModels.py: try to handle encoding errors
|
||||
* src/ImageSelect.py: call fix_encoding to handle path names
|
||||
* src/Utils.py: provide a routine to attempt to fix encoding of
|
||||
str values
|
||||
* src/plugins/Check.py: repair bad filenames
|
||||
|
||||
2005-11-16 Eero Tamminen <eerot@sf>
|
||||
* src/po/fi.po: Translation update to latest template,
|
||||
finetune keyboard shortcuts.
|
||||
|
@ -456,10 +456,16 @@ class MediaModel(BaseModel):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_description(self,data):
|
||||
return unicode(data[4])
|
||||
try:
|
||||
return unicode(data[4])
|
||||
except:
|
||||
return unicode(data[4],'latin1')
|
||||
|
||||
def column_path(self,data):
|
||||
return unicode(data[2])
|
||||
try:
|
||||
return unicode(data[2])
|
||||
except:
|
||||
return unicode(data[2].encode('iso-8859-1'))
|
||||
|
||||
def column_mime(self,data):
|
||||
if data[3]:
|
||||
|
@ -486,10 +486,10 @@ class Gallery(ImageSelect):
|
||||
def on_photolist_drag_data_received(self,w, context, x, y, data, info, time):
|
||||
if data and data.format == 8:
|
||||
icon_index = self.get_index(w,x,y)
|
||||
d = data.data.replace('\0',' ').strip()
|
||||
d = Utils.fix_encoding(data.data.replace('\0',' ').strip())
|
||||
protocol,site,mfile,j,k,l = urlparse.urlparse(d)
|
||||
if protocol == "file":
|
||||
name = mfile
|
||||
name = Utils.fix_encoding(mfile)
|
||||
mime = GrampsMime.get_type(name)
|
||||
photo = RelLib.MediaObject()
|
||||
photo.set_path(name)
|
||||
@ -515,6 +515,7 @@ class Gallery(ImageSelect):
|
||||
t = _("Could not import %s") % d
|
||||
ErrorDialog(t,str(msg))
|
||||
return
|
||||
tfile = Utils.fix_encoding(tfile)
|
||||
mime = GrampsMime.get_type(tfile)
|
||||
photo = RelLib.MediaObject()
|
||||
photo.set_mime_type(mime)
|
||||
|
@ -63,6 +63,19 @@ def history_broken():
|
||||
data_recover_msg = _('The data can only be recovered by Undo operation '
|
||||
'or by quitting with abandoning changes.')
|
||||
|
||||
def fix_encoding(value):
|
||||
import locale
|
||||
if type(value) != unicode:
|
||||
try:
|
||||
return unicode(value)
|
||||
except:
|
||||
codeset = locale.getpreferredencoding()
|
||||
if codeset == 'UTF-8':
|
||||
codeset = 'latin1'
|
||||
return unicode(value,codeset)
|
||||
else:
|
||||
return value
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# force_unicode
|
||||
|
@ -73,8 +73,9 @@ class Check(Tool.Tool):
|
||||
trans.set_batch(True)
|
||||
db.disable_signals()
|
||||
checker = CheckIntegrity(db,parent,trans)
|
||||
checker.fix_encoding()
|
||||
checker.cleanup_missing_photos(cli)
|
||||
|
||||
|
||||
prev_total = -1
|
||||
total = 0
|
||||
|
||||
@ -154,6 +155,31 @@ class CheckIntegrity:
|
||||
self.progress.step()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def fix_encoding(self):
|
||||
import locale
|
||||
codeset = locale.nl_langinfo(locale.CODESET)
|
||||
if codeset == 'UTF-8':
|
||||
codeset = 'latin1'
|
||||
|
||||
self.progress.set_pass(_('Looking for character encoding errors'),
|
||||
self.db.get_number_of_media_objects())
|
||||
|
||||
cursor = self.db.get_media_cursor()
|
||||
value = cursor.first()
|
||||
while value:
|
||||
(handle,data) = value
|
||||
if type(data[2]) != unicode or type(data[4]) != unicode:
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
if type(obj.path) != unicode:
|
||||
obj.path = unicode(obj.path,codeset)
|
||||
if type(obj.desc) != unicode:
|
||||
obj.desc = unicode(obj.desc,codeset)
|
||||
self.db.commit_media_object(obj,self.trans)
|
||||
self.progress.step()
|
||||
value = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
def check_for_broken_family_links(self):
|
||||
# Check persons referenced by the family objects
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user