Fixes for undo

svn: r3089
This commit is contained in:
Don Allingham 2004-04-16 19:15:02 +00:00
parent f40e54f1a9
commit 54e1dd71fa
9 changed files with 157 additions and 112 deletions

View File

@ -262,6 +262,10 @@ class AddSpouse:
self.db.add_transaction(trans) self.db.add_transaction(trans)
Utils.destroy_passed_object(obj) Utils.destroy_passed_object(obj)
self.update(self.active_family) self.update(self.active_family)
m = Marriage.Marriage(self.parent, self.active_family,
self.parent.db, self.parent.new_after_edit,
self.parent.family_view.load_family)
m.on_add_clicked()
def relation_type_changed(self,obj): def relation_type_changed(self,obj):
self.update_data() self.update_data()

View File

@ -80,8 +80,11 @@ class ChooseParents:
self.parent = parent self.parent = parent
self.db = db self.db = db
self.child_windows = {} self.child_windows = {}
self.person = person self.person = self.db.find_person_from_id(person.get_id())
self.family = family if family:
self.family = self.db.find_family_from_id(family.get_id())
else:
self.family = None
self.family_update = family_update self.family_update = family_update
self.full_update = full_update self.full_update = full_update
self.old_type = "" self.old_type = ""
@ -281,7 +284,7 @@ class ChooseParents:
if self.dday and pbday.get_low_year()+10 > self.dday.get_high_year(): if self.dday and pbday.get_low_year()+10 > self.dday.get_high_year():
return 0 return 0
if self.dday and dday.get_year_valid(): if self.dday and self.dday.get_year_valid():
if pbday and pbday.get_year_valid(): if pbday and pbday.get_year_valid():
# reject if parents deathday + 3 < childs birth date # reject if parents deathday + 3 < childs birth date
if pdday and self.bday and pdday.get_high_year()+3 < self.bday.get_low_year(): if pdday and self.bday and pdday.get_high_year()+3 < self.bday.get_low_year():
@ -353,8 +356,16 @@ class ChooseParents:
for family_id in self.db.get_family_keys(): for family_id in self.db.get_family_keys():
family = self.db.find_family_from_id(family_id) family = self.db.find_family_from_id(family_id)
if family.get_father_id() == father_id and family.get_mother_id() == mother_id: if family.get_father_id() == father_id and family.get_mother_id() == mother_id:
trans = self.db.start_transaction()
family.add_child_id(self.person.get_id())
self.db.commit_family(family,trans)
self.db.add_transaction(trans)
return family return family
elif family.get_father_id() == mother_id and family.get_mother_id() == father_id: elif family.get_father_id() == mother_id and family.get_mother_id() == father_id:
trans = self.db.start_transaction()
family.add_child_id(self.person.get_id())
self.db.commit_family(family,trans)
self.db.add_transaction(trans)
return family return family
trans = self.db.start_transaction() trans = self.db.start_transaction()
@ -364,13 +375,13 @@ class ChooseParents:
family.add_child_id(self.person.get_id()) family.add_child_id(self.person.get_id())
if father_id: if father_id:
father = self.db.find_person_from_id(father_id) self.father = self.db.find_person_from_id(father_id)
father.add_family_id(family.get_id()) self.father.add_family_id(family.get_id())
self.db.commit_person(father,trans) self.db.commit_person(self.father,trans)
if mother_id: if mother_id:
mother = self.db.find_person_from_id(mother_id) self.mother = self.db.find_person_from_id(mother_id)
mother.add_family_id(family.get_id()) self.mother.add_family_id(family.get_id())
self.db.commit_person(mother,trans) self.db.commit_person(self.mother,trans)
self.db.commit_family(family,trans) self.db.commit_family(family,trans)
self.db.add_transaction(trans) self.db.add_transaction(trans)
@ -498,8 +509,10 @@ class ChooseParents:
self.family = None self.family = None
if self.family: if self.family:
self.family.add_child_id(self.person.get_id())
self.family.set_relationship(self.type) self.family.set_relationship(self.type)
self.change_family_type(self.family,mother_rel,father_rel) self.change_family_type(self.family,mother_rel,father_rel)
self.db.commit_family(self.family)
self.family_update(None) self.family_update(None)
self.close(obj) self.close(obj)
@ -548,10 +561,11 @@ class ChooseParents:
Changes the family type of the specified family. If the family Changes the family type of the specified family. If the family
is None, the the relationship type shoud be deleted. is None, the the relationship type shoud be deleted.
""" """
if self.person not in family.get_child_id_list(): family_id = family.get_id()
if self.person.get_id() not in family.get_child_id_list():
family.add_child_id(self.person.get_id()) family.add_child_id(self.person.get_id())
for fam in self.person.get_parent_family_id_list(): for fam in self.person.get_parent_family_id_list():
if family == fam[0]: if family_id == fam[0]:
if mother_rel == fam[1] and father_rel == fam[2]: if mother_rel == fam[1] and father_rel == fam[2]:
return return
if mother_rel != fam[1] or father_rel != fam[2]: if mother_rel != fam[1] or father_rel != fam[2]:

View File

@ -654,9 +654,10 @@ class FamilyView:
self.parent.db.commit_family(self.family,trans) self.parent.db.commit_family(self.family,trans)
self.load_family(self.family) self.load_family(self.family)
Marriage.Marriage(self.parent,self.family,self.parent.db, m = Marriage.Marriage(self.parent,self.family,self.parent.db,
self.parent.new_after_edit, self.parent.new_after_edit,
self.load_family) self.load_family)
m.on_add_clicked()
def add_child_clicked(self,obj): def add_child_clicked(self,obj):
if not self.person: if not self.person:
@ -850,8 +851,11 @@ class FamilyView:
def load_family(self,family=None): def load_family(self,family=None):
self.person = self.parent.active_person if self.parent.active_person:
if not self.person: id = self.parent.active_person.get_id()
self.person = self.parent.db.find_person_from_id(id)
else:
self.person = None
self.clear() self.clear()
return return
@ -877,6 +881,7 @@ class FamilyView:
self.spouse_model.clear() self.spouse_model.clear()
self.child_model.clear() self.child_model.clear()
self.sp_parents_model.clear() self.sp_parents_model.clear()
splist = self.person.get_family_id_list() splist = self.person.get_family_id_list()
if len(splist) > 1: if len(splist) > 1:
@ -983,18 +988,19 @@ class FamilyView:
def display_marriage(self,family): def display_marriage(self,family):
self.child_model.clear() self.child_model.clear()
self.family = family
if not family: if not family:
self.family = None
return return
self.family = self.parent.db.find_family_from_id(family.get_id())
if family.get_father_id() == self.person.get_id(): if self.family.get_father_id() == self.person.get_id():
sp_id = family.get_mother_id() sp_id = self.family.get_mother_id()
if sp_id: if sp_id:
self.selected_spouse = self.parent.db.find_person_from_id(sp_id) self.selected_spouse = self.parent.db.find_person_from_id(sp_id)
else: else:
self.selected_spouse = None self.selected_spouse = None
else: else:
sp_id = family.get_father_id() sp_id = self.family.get_father_id()
if sp_id: if sp_id:
self.selected_spouse = self.parent.db.find_person_from_id(sp_id) self.selected_spouse = self.parent.db.find_person_from_id(sp_id)
else: else:
@ -1006,7 +1012,7 @@ class FamilyView:
i = 0 i = 0
fiter = None fiter = None
child_list = list(family.get_child_id_list()) child_list = list(self.family.get_child_id_list())
self.child_map = {} self.child_map = {}
@ -1015,8 +1021,8 @@ class FamilyView:
child = self.parent.db.find_person_from_id(child_id) child = self.parent.db.find_person_from_id(child_id)
for fam in child.get_parent_family_id_list(): for fam in child.get_parent_family_id_list():
if fam[0] == family.get_id(): if fam[0] == self.family.get_id():
if self.person == family.get_father_id(): if self.person == self.family.get_father_id():
status = "%s/%s" % (_(fam[2]),_(fam[1])) status = "%s/%s" % (_(fam[2]),_(fam[1]))
else: else:
status = "%s/%s" % (_(fam[1]),_(fam[2])) status = "%s/%s" % (_(fam[1]),_(fam[2]))
@ -1239,7 +1245,10 @@ class FamilyView:
if not person: if not person:
return return
try: try:
ChooseParents.ChooseParents(self.parent, self.parent.db,person,None, ChooseParents.ChooseParents(self.parent,
self.parent.db,
person,
None,
self.load_family, self.load_family,
self.parent.full_update) self.parent.full_update)
except: except:

View File

@ -646,7 +646,7 @@ class Marriage:
except: except:
pass pass
def on_add_clicked(self,obj): def on_add_clicked(self,*obj):
import EventEdit import EventEdit
name = Utils.family_name(self.family,self.db) name = Utils.family_name(self.family,self.db)
EventEdit.EventEditor(self,name,const.marriageEvents, EventEdit.EventEditor(self,name,const.marriageEvents,

View File

@ -63,6 +63,8 @@ class PeopleModel(gtk.GenericTreeModel):
if not self.db.is_open(): if not self.db.is_open():
return return
import time
t = time.time()
for person_id in self.db.get_person_keys(): for person_id in self.db.get_person_keys():
person = self.db.find_person_from_id(person_id) person = self.db.find_person_from_id(person_id)
@ -91,6 +93,7 @@ class PeopleModel(gtk.GenericTreeModel):
self.path2iter[tpl] = person_id self.path2iter[tpl] = person_id
val += 1 val += 1
sval += 1 sval += 1
print time.time() - t
def byname(self,f,s): def byname(self,f,s):
n1 = self.db.person_map.get(str(f))[2].get_sort_name() n1 = self.db.person_map.get(str(f))[2].get_sort_name()

View File

@ -1970,7 +1970,7 @@ class Family(SourceNote):
def get_id(self) : def get_id(self) :
"""returns the gramps ID for the Family""" """returns the gramps ID for the Family"""
return self.id return unicode(self.id)
def set_relationship(self,type): def set_relationship(self,type):
"""assigns a string indicating the relationship between the """assigns a string indicating the relationship between the
@ -2638,14 +2638,12 @@ class GrampsDB:
return Transaction(msg) return Transaction(msg)
def add_transaction(self,transaction): def add_transaction(self,transaction):
transaction.display()
self.translist.append(transaction) self.translist.append(transaction)
def undo(self): def undo(self):
if len(self.translist) == 0: if len(self.translist) == 0:
return return
transaction = self.translist.pop() transaction = self.translist.pop()
transaction.display()
subitems = transaction.get_data() subitems = transaction.get_data()
subitems.reverse() subitems.reverse()
@ -3297,7 +3295,7 @@ class GrampsDB:
index = self.fprefix % self.fmap_index index = self.fprefix % self.fmap_index
self.fmap_index = self.fmap_index + 1 self.fmap_index = self.fmap_index + 1
family = Family() family = Family()
family.set_id(index) family.set_id(unicode(index))
if trans != None: if trans != None:
trans.add(FAMILY_KEY, index, None) trans.add(FAMILY_KEY, index, None)
self.family_map.put(str(index),family.serialize()) self.family_map.put(str(index),family.serialize())

View File

@ -51,7 +51,7 @@
<accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1899"> <widget class="GtkImage" id="image1916">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-new</property> <property name="stock">gtk-new</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -73,7 +73,7 @@
<accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1900"> <widget class="GtkImage" id="image1917">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-open</property> <property name="stock">gtk-open</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -107,7 +107,7 @@
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1901"> <widget class="GtkImage" id="image1918">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-convert</property> <property name="stock">gtk-convert</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -135,7 +135,7 @@
<accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1902"> <widget class="GtkImage" id="image1919">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-quit</property> <property name="stock">gtk-quit</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -171,7 +171,7 @@
<accelerator key="Insert" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="Insert" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1903"> <widget class="GtkImage" id="image1920">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-add</property> <property name="stock">gtk-add</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -194,7 +194,7 @@
<accelerator key="Delete" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="Delete" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1904"> <widget class="GtkImage" id="image1921">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-remove</property> <property name="stock">gtk-remove</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -240,7 +240,7 @@
<accelerator key="F" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="F" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1905"> <widget class="GtkImage" id="image1922">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-find</property> <property name="stock">gtk-find</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -262,7 +262,7 @@
<accelerator key="M" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="M" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1906"> <widget class="GtkImage" id="image1923">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-convert</property> <property name="stock">gtk-convert</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -289,7 +289,7 @@
<signal name="activate" handler="on_preferences1_activate"/> <signal name="activate" handler="on_preferences1_activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1907"> <widget class="GtkImage" id="image1924">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-preferences</property> <property name="stock">gtk-preferences</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -310,7 +310,7 @@
<signal name="activate" handler="on_column_order_activate" last_modification_time="Wed, 10 Mar 2004 04:36:07 GMT"/> <signal name="activate" handler="on_column_order_activate" last_modification_time="Wed, 10 Mar 2004 04:36:07 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1908"> <widget class="GtkImage" id="image1925">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-properties</property> <property name="stock">gtk-properties</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -331,7 +331,7 @@
<signal name="activate" handler="on_default_person_activate" last_modification_time="Sat, 16 Aug 2003 01:58:26 GMT"/> <signal name="activate" handler="on_default_person_activate" last_modification_time="Sat, 16 Aug 2003 01:58:26 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1909"> <widget class="GtkImage" id="image1926">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-home</property> <property name="stock">gtk-home</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -386,21 +386,6 @@
<signal name="activate" handler="on_toolbar2_activate" last_modification_time="Fri, 17 Oct 2003 04:41:03 GMT"/> <signal name="activate" handler="on_toolbar2_activate" last_modification_time="Fri, 17 Oct 2003 04:41:03 GMT"/>
</widget> </widget>
</child> </child>
<child>
<widget class="GtkMenuItem" id="separator12">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="event_history">
<property name="visible">True</property>
<property name="label" translatable="yes">_Event History...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_event_history_activate" last_modification_time="Wed, 31 Mar 2004 03:28:28 GMT"/>
</widget>
</child>
</widget> </widget>
</child> </child>
</widget> </widget>
@ -432,7 +417,7 @@
<accelerator key="D" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="D" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1910"> <widget class="GtkImage" id="image1927">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-index</property> <property name="stock">gtk-index</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -454,7 +439,7 @@
<accelerator key="B" modifiers="GDK_CONTROL_MASK" signal="activate"/> <accelerator key="B" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1911"> <widget class="GtkImage" id="image1928">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property> <property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -527,7 +512,7 @@
<accelerator key="F1" modifiers="0" signal="activate"/> <accelerator key="F1" modifiers="0" signal="activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1912"> <widget class="GtkImage" id="image1929">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-help</property> <property name="stock">gtk-help</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -548,7 +533,7 @@
<signal name="activate" handler="on_faq_activate" last_modification_time="Wed, 26 Nov 2003 17:59:23 GMT"/> <signal name="activate" handler="on_faq_activate" last_modification_time="Wed, 26 Nov 2003 17:59:23 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1913"> <widget class="GtkImage" id="image1930">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property> <property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -575,7 +560,7 @@
<signal name="activate" handler="on_gramps_home_page_activate"/> <signal name="activate" handler="on_gramps_home_page_activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1914"> <widget class="GtkImage" id="image1931">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-jump-to</property> <property name="stock">gtk-jump-to</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -596,7 +581,7 @@
<signal name="activate" handler="on_gramps_mailing_lists_activate"/> <signal name="activate" handler="on_gramps_mailing_lists_activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1915"> <widget class="GtkImage" id="image1932">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gnome-stock-mail</property> <property name="stock">gnome-stock-mail</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -650,7 +635,7 @@
<signal name="activate" handler="on_about_activate" last_modification_time="Tue, 01 Apr 2003 03:44:24 GMT"/> <signal name="activate" handler="on_about_activate" last_modification_time="Tue, 01 Apr 2003 03:44:24 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image1916"> <widget class="GtkImage" id="image1933">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gnome-stock-about</property> <property name="stock">gnome-stock-about</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>

View File

@ -1302,13 +1302,13 @@ class Gramps:
self.people_view.goto_active_person(first) self.people_view.goto_active_person(first)
def change_active_person(self,person,force=0): def change_active_person(self,person,force=0):
self.active_person = person
if person == None: if person == None:
self.set_buttons(0) self.set_buttons(0)
self.active_person = None self.active_person = None
self.modify_statusbar() self.modify_statusbar()
elif self.active_person == None or \ elif self.active_person == None or \
person.get_id() != self.active_person.get_id(): person.get_id() != self.active_person.get_id():
self.active_person = self.db.find_person_from_id(person.get_id())
self.modify_statusbar() self.modify_statusbar()
self.set_buttons(1) self.set_buttons(1)
if person: if person:
@ -1334,6 +1334,7 @@ class Gramps:
self.backbtn.set_sensitive(0) self.backbtn.set_sensitive(0)
self.back.set_sensitive(0) self.back.set_sensitive(0)
else: else:
self.active_person = self.db.find_person_from_id(person.get_id())
self.set_buttons(1) self.set_buttons(1)
def modify_statusbar(self): def modify_statusbar(self):

View File

@ -89,27 +89,31 @@ class CheckIntegrity:
def check_for_broken_family_links(self): def check_for_broken_family_links(self):
self.broken_links = [] self.broken_links = []
for key in self.db.get_family_id_map().keys(): for family_id in self.db.get_family_keys():
family = self.db.get_family_id(key) family = self.db.find_family_from_id(family_id)
father = family.get_father_id() father = self.db.find_family_from_id(family.get_father_id())
mother = family.get_mother_id() mother = self.db.find_family_from_id(family.get_mother_id())
if father and family not in father.get_family_id_list(): if father and family_id not in father.get_family_id_list():
Utils.modified() Utils.modified()
self.broken_parent_links.append((father,family)) self.broken_parent_links.append((father,family))
father.add_family_id(family) father.add_family_id(family_id)
if mother and family not in mother.get_family_id_list(): self.db.commit_person(father)
if mother and family_id not in mother.get_family_id_list():
Utils.modified() Utils.modified()
self.broken_parent_links.append((mother,family)) self.broken_parent_links.append((mother,family))
mother.add_family_id(family) mother.add_family_id(family_id)
for child in family.get_child_id_list(): self.db.commit_person(mother)
for child_id in family.get_child_id_list():
child = self.db.find_person_from_id(child_id)
if family == child.get_main_parents_family_id(): if family == child.get_main_parents_family_id():
continue continue
for family_type in child.get_parent_family_id_list(): for family_type in child.get_parent_family_id_list():
if family_type[0] == family: if family_type[0] == family_id:
break break
else: else:
family.remove_child_id(child) family.remove_child_id(child_id)
self.db.commit_family(family)
Utils.modified() Utils.modified()
self.broken_links.append((child,family)) self.broken_links.append((child,family))
@ -118,45 +122,64 @@ class CheckIntegrity:
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def remove_clicked(): def remove_clicked():
# File is lost => remove all references and the object itself # File is lost => remove all references and the object itself
for p in self.db.get_family_id_map().values(): for person_id in self.db.get_family_keys():
p = self.db.find_family_from_id(person_id)
nl = p.get_media_list() nl = p.get_media_list()
changed = 0
for o in nl: for o in nl:
if o.get_reference_id() == ObjectId: if o.get_reference_id() == ObjectId:
changed = 1
nl.remove(o) nl.remove(o)
if changed:
p.set_media_list(nl) p.set_media_list(nl)
self.db.commit_person(p)
for key in self.db.get_person_keys(): for key in self.db.get_person_keys():
p = self.db.get_person(key) p = self.db.find_person_from_id(key)
nl = p.get_media_list() nl = p.get_media_list()
changed = 0
for o in nl: for o in nl:
if o.get_reference_id() == ObjectId: if o.get_reference_id() == ObjectId:
changed = 1
nl.remove(o) nl.remove(o)
if changed:
p.set_media_list(nl) p.set_media_list(nl)
self.db.commit_person(p)
for key in self.db.get_source_keys(): for key in self.db.get_source_keys():
p = self.db.get_source(key) p = self.db.find_source_from_id(key)
nl = p.get_media_list() nl = p.get_media_list()
changed = 0
for o in nl: for o in nl:
if o.get_reference_id() == ObjectId: if o.get_reference_id() == ObjectId:
changed = 1
nl.remove(o) nl.remove(o)
if changed:
p.set_media_list(nl) p.set_media_list(nl)
self.db.commit_source(p)
for key in self.db.get_place_id_keys(): for key in self.db.get_place_id_keys():
p = self.db.get_place_id(key) p = self.db.get_place_id(key)
nl = p.get_media_list() nl = p.get_media_list()
changed = 0
for o in nl: for o in nl:
if o.get_reference_id() == ObjectId: if o.get_reference_id() == ObjectId:
changed = 1
nl.remove(o) nl.remove(o)
if changed:
p.set_media_list(nl) p.set_media_list(nl)
self.db.commit_place(p)
self.removed_photo.append(ObjectId) self.removed_photo.append(ObjectId)
self.db.remove_object(ObjectId) self.db.remove_object(ObjectId)
Utils.modified() Utils.modified()
def leave_clicked(): def leave_clicked():
self.bad_photo.append(ObjectMap[ObjectId]) self.bad_photo.append(ObjectId)
def select_clicked(): def select_clicked():
# File is lost => select a file to replace the lost one # File is lost => select a file to replace the lost one
def fs_close_window(obj): def fs_close_window(obj):
self.bad_photo.append(ObjectMap[ObjectId]) self.bad_photo.append(ObjectId)
def fs_ok_clicked(obj): def fs_ok_clicked(obj):
name = fs_top.get_filename() name = fs_top.get_filename()
@ -166,9 +189,9 @@ class CheckIntegrity:
shutil.copystat(name,photo_name) shutil.copystat(name,photo_name)
except: except:
pass pass
self.replaced_photo.append(ObjectMap[ObjectId]) self.replaced_photo.append(ObjectId)
else: else:
self.bad_photo.append(ObjectMap[ObjectId]) self.bad_photo.append(ObjectId)
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file")) fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
fs_top.hide_fileop_buttons() fs_top.hide_fileop_buttons()
@ -178,14 +201,15 @@ class CheckIntegrity:
fs_top.destroy() fs_top.destroy()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
ObjectMap = self.db.get_object_map()
for ObjectId in ObjectMap.keys(): for ObjectId in self.db.get_object_keys():
photo_name = ObjectMap[ObjectId].get_path() obj = self.db.find_object_from_id(ObjectId)
photo_name = obj.get_path()
if not os.path.isfile(photo_name): if not os.path.isfile(photo_name):
if cl: if cl:
print "Warning: media file %s was not found." \ print "Warning: media file %s was not found." \
% os.path.basename(photo_name) % os.path.basename(photo_name)
self.bad_photo.append(ObjectMap[ObjectId]) self.bad_photo.append(ObjectId)
else: else:
if missmedia_action == 0: if missmedia_action == 0:
mmd = MissingMediaDialog(_("Media object could not be found"), mmd = MissingMediaDialog(_("Media object could not be found"),
@ -204,8 +228,8 @@ class CheckIntegrity:
select_clicked() select_clicked()
def cleanup_empty_families(self,automatic): def cleanup_empty_families(self,automatic):
for key in self.db.get_family_id_map().keys(): for key in self.db.get_family_keys():
family = self.db.get_family_id(key) family = self.db.find_family_from_id(key)
if family.get_father_id() == None and family.get_mother_id() == None: if family.get_father_id() == None and family.get_mother_id() == None:
Utils.modified() Utils.modified()
self.empty_family.append(family) self.empty_family.append(family)
@ -213,28 +237,32 @@ class CheckIntegrity:
def delete_empty_family(self,family): def delete_empty_family(self,family):
for key in self.db.get_person_keys(): for key in self.db.get_person_keys():
child = self.db.get_person(key) child = self.db.find_person_from_id(key)
child.remove_parent_family_id(family.get_id()) child.remove_parent_family_id(family.get_id())
child.remove_family_id(family.get_id()) child.remove_family_id(family.get_id())
self.db.delete_family(family.get_id()) self.db.delete_family(family.get_id())
def check_parent_relationships(self): def check_parent_relationships(self):
for key in self.db.get_family_id_map().keys(): for key in self.db.get_family_keys():
family = self.db.get_family_id(key) family = self.db.find_family_from_id(key)
father = family.get_father_id() mother_id = family.get_mother_id()
mother = family.get_mother_id() father_id = family.get_father_id()
father = self.db.find_family_from_id(father_id)
mother = self.db.find_family_from_id(mother_id)
type = family.get_relationship() type = family.get_relationship()
if not father and not mother: if not father and not mother:
continue continue
elif father == None: elif father == None:
if mother.get_gender() == RelLib.Person.male: if mother.get_gender() == RelLib.Person.male:
family.set_father_id(mother) family.set_father_id(mother_id)
family.set_mother_id(None) family.set_mother_id(None)
self.db.commit_family(family)
elif mother == None: elif mother == None:
if father.get_gender() == RelLib.Person.female: if father.get_gender() == RelLib.Person.female:
family.set_mother_id(father) family.set_mother_id(father_id)
family.set_father_id(None) family.set_father_id(None)
self.db.commit_family(family)
else: else:
fgender = father.get_gender() fgender = father.get_gender()
mgender = mother.get_gender() mgender = mother.get_gender()
@ -242,16 +270,19 @@ class CheckIntegrity:
if fgender == mgender and fgender != RelLib.Person.unknown: if fgender == mgender and fgender != RelLib.Person.unknown:
family.set_relationship("Partners") family.set_relationship("Partners")
self.fam_rel.append(family) self.fam_rel.append(family)
self.db.commit_family(family)
elif fgender == RelLib.Person.female or mgender == RelLib.Person.male: elif fgender == RelLib.Person.female or mgender == RelLib.Person.male:
family.set_father_id(mother) family.set_father_id(mother_id)
family.set_mother_id(father) family.set_mother_id(father_id)
self.fam_rel.append(family) self.fam_rel.append(family)
self.db.commit_family(family)
elif fgender != mgender: elif fgender != mgender:
family.set_relationship("Unknown") family.set_relationship("Unknown")
self.fam_rel.append(family) self.fam_rel.append(family)
if fgender == RelLib.Person.female or mgender == RelLib.Person.male: if fgender == RelLib.Person.female or mgender == RelLib.Person.male:
family.set_father_id(mother) family.set_father_id(mother_id)
family.set_mother_id(father) family.set_mother_id(father_id)
self.db.commit_family(family)
def build_report(self,cl=0): def build_report(self,cl=0):
bad_photos = len(self.bad_photo) bad_photos = len(self.bad_photo)
@ -281,8 +312,8 @@ class CheckIntegrity:
self.text.write(_("%d broken child/family links were found\n") % blink) self.text.write(_("%d broken child/family links were found\n") % blink)
for c in self.broken_links: for c in self.broken_links:
cn = c[0].get_primary_name().get_name() cn = c[0].get_primary_name().get_name()
f = c[1].get_father_id() f = self.db.find_person_from_id(c[1].get_father_id())
m = c[1].get_mother_id() m = self.db.find_person_from_id(c[1].get_mother_id())
if f and m: if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\ pn = _("%s and %s") % (f.get_primary_name().get_name(),\
m.get_primary_name().get_name()) m.get_primary_name().get_name())
@ -302,8 +333,8 @@ class CheckIntegrity:
self.text.write(_("%d broken spouse/family links were found\n") % plink) self.text.write(_("%d broken spouse/family links were found\n") % plink)
for c in self.broken_parent_links: for c in self.broken_parent_links:
cn = c[0].get_primary_name().get_name() cn = c[0].get_primary_name().get_name()
f = c[1].get_father_id() f = self.db.find_person_from_id(c[1].get_father_id())
m = c[1].get_mother_id() m = self.db.find_person_from_id(c[1].get_mother_id())
if f and m: if f and m:
pn = _("%s and %s") % (f.get_primary_name().get_name(),\ pn = _("%s and %s") % (f.get_primary_name().get_name(),\
m.get_primary_name().get_name()) m.get_primary_name().get_name())