diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e5555f3d0..43be53670 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2005-11-16 Don Allingham + * 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 * src/po/fi.po: Translation update to latest template, finetune keyboard shortcuts. diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index 98b43766d..5ded1eab8 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -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]: diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index 03dfb88b2..0a4c7ef7b 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -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) diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 84c488a7a..36b63d3cd 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -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 diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 3fd286a57..f5b36376c 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -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