diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index c7d8a9b43..1de248697 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2005-08-24 Don Allingham + * src/ImgManip.py: convert to png instead of jpeg + * src/ReadGedcom.py: try to catch bad secondary index error. + * src/ReportUtils.py: provide privacy sanitation on a list + * src/NavWebPage.py: better handling of thumbnails, allow gallery + page to be disabled + 2005-08-24 Martin Hawlisch * src/ImgManip.py: import Utils (required by get_thumbnail_image) diff --git a/gramps2/src/ImgManip.py b/gramps2/src/ImgManip.py index 6ba41aa95..03a55f065 100644 --- a/gramps2/src/ImgManip.py +++ b/gramps2/src/ImgManip.py @@ -35,7 +35,7 @@ class ImgManip: def size(self): try: img = gtk.gdk.pixbuf_new_from_file(self.src) - except GError: + except gobject.GError: return (0,0) return (img.get_width(),img.get_height()) @@ -101,7 +101,7 @@ class ImgManip: def _build_thumb_path(path): base = os.path.expanduser('~/.gramps/thumb') m = md5.md5(path) - return os.path.join(base,m.hexdigest()+'.jpg') + return os.path.join(base,m.hexdigest()+'.png') def run_thumbnailer(cmd, frm, to): sublist = { @@ -132,7 +132,7 @@ def set_thumbnail_image(path,mtype=None): ph = int(h*scale) pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR) - pixbuf.save(_build_thumb_path(path),"jpeg") + pixbuf.save(_build_thumb_path(path),"png") except: print "Could not create thumbnail for",path,mtype diff --git a/gramps2/src/ReadGedcom.py b/gramps2/src/ReadGedcom.py index 4e4b823ce..1ad720f49 100644 --- a/gramps2/src/ReadGedcom.py +++ b/gramps2/src/ReadGedcom.py @@ -57,6 +57,7 @@ from ansel_utf8 import ansel_to_utf8 import latin_utf8 import Utils import GrampsMime +from bsddb import db from GedcomInfo import * from QuestionDialog import ErrorDialog @@ -207,6 +208,13 @@ def import2(database, filename, cb, codeset, use_trans): Utils.destroy_passed_object(statusWindow) ErrorDialog(m1,m2) return + except db.DBSecondaryBadError, msg: + Utils.destroy_passed_object(statusWindow) + WarningDialog(_('Database corruption detected'), + _('A problem was detected with the database. Please ' + 'run the Check and Repair Database tool to fix the ' + 'problem.')) + return except: Utils.destroy_passed_object(statusWindow) DisplayTrace.DisplayTrace() diff --git a/gramps2/src/ReportUtils.py b/gramps2/src/ReportUtils.py index 377c0aa53..57fede416 100644 --- a/gramps2/src/ReportUtils.py +++ b/gramps2/src/ReportUtils.py @@ -273,6 +273,13 @@ def estimate_age(db, person, end_handle=None, start_handle=None): age = (lower,upper) return age +def sanitize_list(obj_list,exclude_private): + if exclude_private: + return [obj for obj in obj_list if not obj.private] + else: + return obj_list + + def sanitize_person(db,person): """ Creates a new Person instance based off the passed Person diff --git a/gramps2/src/plugins/NavWebPage.py b/gramps2/src/plugins/NavWebPage.py index 1a0e951ca..f0e6c7fe2 100644 --- a/gramps2/src/plugins/NavWebPage.py +++ b/gramps2/src/plugins/NavWebPage.py @@ -128,6 +128,7 @@ class BasePage: self.noid = options.handler.options_dict['NWEBnoid'] self.use_intro = options.handler.options_dict['NWEBintronote'] != u"" self.use_contact = options.handler.options_dict['NWEBcontact'] != u"" + self.use_gallery = options.handler.options_dict['NWEBgallery'] self.header = options.handler.options_dict['NWEBheader'] self.footer = options.handler.options_dict['NWEBfooter'] self.photo_list = photo_list @@ -153,8 +154,8 @@ class BasePage: self.photo_list[handle] = [lnk] ext = os.path.splitext(photo.get_path())[1] - real_path = os.path.join(self.build_path(handle,'images'),handle+ext) - thumb_path = os.path.join(self.build_path(handle,'thumb'),handle+ext) + real_path = "%s/%s" % (self.build_path(handle,'images'),handle+ext) + thumb_path = "%s/%s" % (self.build_path(handle,'thumb'),handle+ext) return (real_path,thumb_path) def create_file(self,name): @@ -281,7 +282,8 @@ class BasePage: self.show_link(of,'individuals',_('Individuals'),path) self.show_link(of,'sources',_('Sources'),path) self.show_link(of,'places',_('Places'),path) - self.show_link(of,'gallery',_('Gallery'),path) + if self.use_gallery: + self.show_link(of,'gallery',_('Gallery'),path) if self.inc_download: self.show_link(of,'download',_('Download'),path) if self.use_contact: @@ -296,7 +298,8 @@ class BasePage: of.write(' %s\n' % (lpath,self.ext,title)) def display_first_image_as_thumbnail( self, of, db, photolist=None): - if not photolist: + + if not photolist or not self.use_gallery: return photo_handle = photolist[0].get_reference_handle() @@ -304,30 +307,13 @@ class BasePage: mime_type = photo.get_mime_type() if mime_type: - if mime_type.startswith('image') or mime_type == "application/pdf": - try: - (real_path,newpath) = self.copy_media(photo) - of.write('
\n') - self.media_link(of,photo_handle,newpath,'',up=True) - of.write('
\n') - except (IOError,OSError),msg: - WarningDialog(_("Could not add photo to page"),str(msg)) - elif mime_type.startswith('video/'): - try: - (real_path,newpath) = self.copy_media(photo) - of.write('
\n') - self.media_link(of,photo_handle,newpath,'',up=True) - of.write('
\n') - except (IOError,OSError),msg: - WarningDialog(_("Could not add photo to page"),str(msg)) - else: - try: - (real_path,newpath) = self.copy_media(photo) - of.write('
\n') - self.doc_link(of,photo_handle, '', up=True) - of.write('
\n') - except (IOError,OSError),msg: - WarningDialog(_("Could not add photo to page"),str(msg)) + try: + (real_path,newpath) = self.copy_media(photo) + of.write('
\n') + self.media_link(of,photo_handle,newpath,'',up=True) + of.write('
\n') + except (IOError,OSError),msg: + WarningDialog(_("Could not add photo to page"),str(msg)) def display_additional_images_as_gallery( self, of, db, photolist=None): @@ -341,14 +327,7 @@ class BasePage: photo = db.get_object_from_handle(photo_handle) mime_type = photo.get_mime_type() - if mime_type.startswith('image') or mime_type == "application/pdf": - try: - (real_path,newpath) = self.copy_media(photo) - self.media_link(of,photo_handle,newpath, - photo.get_description(),up=True) - except (IOError,OSError),msg: - WarningDialog(_("Could not add photo to page"),str(msg)) - elif mime_type.startswith('video/'): + if mime_type: try: (real_path,newpath) = self.copy_media(photo) self.media_link(of,photo_handle,newpath, @@ -466,8 +445,7 @@ class BasePage: of.write('
\n') of.write('

' % (dirpath,handle,self.ext)) of.write('%s' % (const.thumbScale,name)) - of.write('

\n') + of.write('alt="%s" />

\n' % name) if usedescr: of.write('

%s

\n' % name) of.write('
\n') @@ -713,7 +691,9 @@ class PlacePage(BasePage): of.write('\n') of.write('\n') - self.display_additional_images_as_gallery(of, db, place.get_media_list()) + if self.use_gallery: + plist = place.get_media_list() + self.display_additional_images_as_gallery(of, db, plist) self.display_note_object(of, place.get_note_object()) self.display_url_list(of, place.get_url_list()) self.display_references(of,db,place_list[place.handle]) @@ -751,12 +731,10 @@ class MediaPage(BasePage): os.path.join(self.html_dir,newpath)) mime_type = photo.get_mime_type() - if mime_type and (mime_type.startswith("image") or - mime_type.startswith('video') or - mime_type == "application/pdf"): + if mime_type: ext = os.path.splitext(photo.get_path())[1] to_dir = self.build_path(handle,'thumb') - to_path = os.path.join(to_dir,handle+ext) + to_path = os.path.join(to_dir,handle+".png") from_path = ImgManip.get_thumbnail_path(photo.get_path(),mime_type) if not os.path.isfile(from_path): from_path = os.path.join(const.dataDir,"document.png") @@ -799,24 +777,17 @@ class MediaPage(BasePage): of.write('%s\n' % (newpath, self.page_title)) of.write('\n') - elif mime_type and mime_type == "application/pdf" or mime_type.startswith('video/'): - ext = os.path.splitext(photo.get_path())[1] - to_dir = self.build_path(handle,'thumb') - path = os.path.join(to_dir,handle+ext) - of.write('\n') else: - path = os.path.join('images','document.png') + thmb_path = ImgManip.get_thumbnail_path(photo.get_path(),photo.get_mime_type()) + if os.path.isfile(thmb_path): + path = "%s/%s.png" % (self.build_path(photo.handle,"images"),photo.handle) + else: + path = os.path.join('images','document.png') of.write('\n') + of.write('\n\n') of.write('\n') @@ -1250,12 +1221,18 @@ class IndividualPage(BasePage): self.display_ind_relationships(of) media_list = [] - photolist = self.person.get_media_list() + photolist = ReportUtils.sanitize_list(self.person.get_media_list(), + self.exclude_private) if len(photolist) > 1: media_list = photolist[1:] for handle in self.person.get_family_handle_list(): family = self.db.get_family_from_handle(handle) - media_list = media_list + family.get_media_list() + media_list += ReportUtils.sanitize_list(family.get_media_list(), + self.exclude_private) + for handle in self.person.get_event_list(): + event = self.db.get_event_from_handle(handle) + media_list += ReportUtils.sanitize_list(event.get_media_list(), + self.exclude_private) self.display_additional_images_as_gallery(of, db, media_list) self.display_note_object(of, self.person.get_note_object()) @@ -1730,6 +1707,7 @@ class WebReport(Report.Report): self.noid = options.handler.options_dict['NWEBnoid'] self.title = options.handler.options_dict['NWEBtitle'] self.sort = Sort.Sort(self.database) + self.inc_gallery = bool(options.handler.options_dict['NWEBgallery']) self.inc_contact = options.handler.options_dict['NWEBcontact'] != u"" self.inc_download = options.handler.options_dict['NWEBdownload'] self.user_header = options.handler.options_dict['NWEBheader'] @@ -1819,7 +1797,8 @@ class WebReport(Report.Report): self.surname_pages(ind_list,archive) self.place_pages(place_list, source_list, archive) self.source_pages(source_list, self.photo_list, archive) - self.gallery_pages(self.photo_list, source_list, archive) + if self.inc_gallery: + self.gallery_pages(self.photo_list, source_list, archive) if archive: archive.close() @@ -1964,7 +1943,8 @@ class WebReport(Report.Report): total = len(self.photo_list) index = 1 photo_keys = self.photo_list.keys() - + photo_keys.sort(self.by_media_title) + for photo_handle in photo_keys: if index == total: next = None @@ -1980,6 +1960,14 @@ class WebReport(Report.Report): prev = photo_handle index += 1 + def by_media_title(self,a_id,b_id): + """Sort routine for comparing two events by their dates. """ + if not (a_id and b_id): + return False + a = self.database.get_object_from_handle(a_id) + b = self.database.get_object_from_handle(b_id) + return cmp(a.desc,b.desc) + def base_pages(self, photo_list, archive): if self.use_home: @@ -2036,6 +2024,7 @@ class WebReportOptions(ReportOptions.ReportOptions): 'NWEBnonames' : 0, 'NWEBnoid' : 0, 'NWEBcontact' : '', + 'NWEBgallery' : 1, 'NWEBheader' : '', 'NWEBfooter' : '', 'NWEBdownload' : 0, @@ -2095,6 +2084,7 @@ class WebReportOptions(ReportOptions.ReportOptions): title_msg = _("Web site title") ext_msg = _("File extension") contact_msg = _("Publisher contact/Note ID") + gallery_msg = _("Include images and media objects") download_msg = _("Include download page") self.no_private = gtk.CheckButton(priv_msg) @@ -2106,6 +2096,9 @@ class WebReportOptions(ReportOptions.ReportOptions): self.restrict_living = gtk.CheckButton(restrict_msg) self.restrict_living.connect('toggled',self.restrict_toggled) + self.include_gallery = gtk.CheckButton(gallery_msg) + self.include_gallery.set_active(self.options_dict['NWEBgallery']) + self.restrict_years = gtk.Entry() self.restrict_years.set_text(str(self.options_dict['NWEBrestrictyears'])) self.restrict_years.set_sensitive(False) @@ -2200,11 +2193,11 @@ class WebReportOptions(ReportOptions.ReportOptions): media_list.sort() html_list.sort() - self.home_note = build_combo_box(media_list,self.options_dict['NWEBhomenote']) - self.intro_note = build_combo_box(media_list,self.options_dict['NWEBintronote']) - self.contact = build_combo_box(media_list,self.options_dict['NWEBcontact']) - self.header = build_combo_box(html_list,self.options_dict['NWEBheader']) - self.footer = build_combo_box(html_list,self.options_dict['NWEBfooter']) + self.home_note = mk_combobox(media_list,self.options_dict['NWEBhomenote']) + self.intro_note = mk_combobox(media_list,self.options_dict['NWEBintronote']) + self.contact = mk_combobox(media_list,self.options_dict['NWEBcontact']) + self.header = mk_combobox(html_list,self.options_dict['NWEBheader']) + self.footer = mk_combobox(html_list,self.options_dict['NWEBfooter']) dialog.add_frame_option(title,_('Home Media/Note ID'), self.home_note) @@ -2213,6 +2206,7 @@ class WebReportOptions(ReportOptions.ReportOptions): dialog.add_frame_option(title,contact_msg,self.contact) dialog.add_frame_option(title,_('HTML user header'),self.header) dialog.add_frame_option(title,_('HTML user footer'),self.footer) + dialog.add_frame_option(title,'',self.include_gallery) dialog.add_frame_option(title,None,self.inc_download) dialog.add_frame_option(title,None,self.noid) @@ -2233,6 +2227,7 @@ class WebReportOptions(ReportOptions.ReportOptions): self.options_dict['NWEBincpriv'] = int(not self.no_private.get_active()) self.options_dict['NWEBnoid'] = int(self.noid.get_active()) self.options_dict['NWEBcontact'] = unicode(self.contact.get_handle()) + self.options_dict['NWEBgallery'] = self.include_gallery.get_active() self.options_dict['NWEBheader'] = unicode(self.header.get_handle()) self.options_dict['NWEBfooter'] = unicode(self.footer.get_handle()) self.options_dict['NWEBdownload'] = int(self.inc_download.get_active()) @@ -2480,7 +2475,7 @@ class GrampsNoteComboBox(gtk.ComboBox): handle = self.local_store.get_value(active,1) return handle -def build_combo_box(media_list,select_value): +def mk_combobox(media_list,select_value): store = gtk.ListStore(str,str) node = None