2004-11-25 11:12:31 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-14 11:02:06 +05:30
|
|
|
# Copyright (C) 2004-2007 Donald N. Allingham
|
2004-11-25 11:12:31 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
# $Id:RecentFiles.py 9912 2008-01-22 09:17:46Z acraphae $
|
2004-11-25 11:12:31 +05:30
|
|
|
|
|
|
|
# Written by Alex Roitman
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import time
|
2005-02-19 06:19:49 +05:30
|
|
|
from xml.parsers.expat import ParserCreate
|
2004-11-25 11:12:31 +05:30
|
|
|
|
2005-12-30 09:27:31 +05:30
|
|
|
try:
|
|
|
|
import fcntl
|
|
|
|
use_lock = True
|
|
|
|
except:
|
|
|
|
use_lock = False
|
|
|
|
|
2006-03-29 09:41:17 +05:30
|
|
|
import const
|
2005-12-30 09:27:31 +05:30
|
|
|
|
2004-11-25 11:12:31 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
GRAMPS_FILENAME = os.path.join(const.HOME_DIR,"recent-files-gramps.xml")
|
2004-11-29 10:45:41 +05:30
|
|
|
MAX_GRAMPS_ITEMS = 10
|
2004-11-25 11:12:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2007-06-14 11:02:06 +05:30
|
|
|
# RecentItem
|
2004-11-25 11:12:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-06-14 11:02:06 +05:30
|
|
|
class RecentItem:
|
2004-11-25 11:12:31 +05:30
|
|
|
"""
|
2004-11-29 10:45:41 +05:30
|
|
|
Interface to a single GRAMPS recent-items item
|
|
|
|
"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,p="", n="",t=0):
|
2004-11-29 10:45:41 +05:30
|
|
|
self.path = p
|
2007-06-14 11:02:06 +05:30
|
|
|
self.name = n
|
2004-11-29 10:45:41 +05:30
|
|
|
self.time = t
|
|
|
|
|
|
|
|
def set_path(self,val):
|
|
|
|
self.path = val
|
|
|
|
|
|
|
|
def get_path(self):
|
|
|
|
return self.path
|
|
|
|
|
2007-06-14 11:02:06 +05:30
|
|
|
def set_name(self,val):
|
|
|
|
self.name = val
|
2004-11-29 10:45:41 +05:30
|
|
|
|
2007-06-14 11:02:06 +05:30
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
2004-11-29 10:45:41 +05:30
|
|
|
|
|
|
|
def set_time(self,val):
|
|
|
|
self.time = int(val)
|
|
|
|
|
|
|
|
def get_time(self):
|
|
|
|
return self.time
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __cmp__(self, other_item):
|
|
|
|
return cmp(self.time, other_item.time)
|
2004-11-29 10:45:41 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2007-06-14 11:02:06 +05:30
|
|
|
# RecentFiles
|
2004-11-25 11:12:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-06-14 11:02:06 +05:30
|
|
|
class RecentFiles:
|
2004-11-25 11:12:31 +05:30
|
|
|
"""
|
2007-06-14 11:02:06 +05:30
|
|
|
Interface to a RecentFiles collection
|
2004-11-29 10:45:41 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2007-06-14 11:02:06 +05:30
|
|
|
gramps_parser = RecentParser()
|
2004-11-29 10:45:41 +05:30
|
|
|
self.gramps_recent_files = gramps_parser.get()
|
|
|
|
|
|
|
|
def add(self,item2add):
|
|
|
|
# First we need to walk the existing items to see
|
|
|
|
# if our item is already there
|
|
|
|
for item in self.gramps_recent_files:
|
|
|
|
if item.get_path() == item2add.get_path():
|
|
|
|
# Found it -- modify timestamp and add all groups
|
|
|
|
# to the item's groups
|
|
|
|
item.set_time(item2add.get_time())
|
|
|
|
return
|
|
|
|
# At this point we walked the items and not found one,
|
|
|
|
# so simply inserting a new item in the beginning
|
|
|
|
self.gramps_recent_files.insert(0,item2add)
|
|
|
|
|
2007-12-19 22:10:08 +05:30
|
|
|
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def rename_filename(self,filename, new_filename):
|
2009-02-10 05:07:40 +05:30
|
|
|
# First we need to walk the existing items to see
|
|
|
|
# if our item is already there
|
2007-12-19 22:10:08 +05:30
|
|
|
found = False
|
|
|
|
for index in range(len(self.gramps_recent_files)):
|
|
|
|
if self.gramps_recent_files[index].get_name() == filename:
|
|
|
|
# Found it -- break here and change that item
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
if found:
|
2008-01-10 21:58:46 +05:30
|
|
|
self.gramps_recent_files[index].set_name(new_filename)
|
2007-12-19 22:10:08 +05:30
|
|
|
|
2004-11-30 07:46:30 +05:30
|
|
|
def remove_filename(self,filename):
|
|
|
|
# First we need to walk the existing items to see
|
|
|
|
# if our item is already there
|
|
|
|
found = False
|
|
|
|
for index in range(len(self.gramps_recent_files)):
|
2007-12-19 22:10:08 +05:30
|
|
|
if self.gramps_recent_files[index].get_name() == filename:
|
2004-11-30 07:46:30 +05:30
|
|
|
# Found it -- break here and pop that item
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
if found:
|
|
|
|
self.gramps_recent_files.pop(index)
|
|
|
|
|
2007-12-19 22:10:08 +05:30
|
|
|
|
|
|
|
def check_if_recent(self,filename):
|
|
|
|
# First we need to walk the existing items to see
|
|
|
|
# if our item is already there
|
|
|
|
found = False
|
|
|
|
for index in range(len(self.gramps_recent_files)):
|
|
|
|
if self.gramps_recent_files[index].get_name() == filename:
|
|
|
|
# Found it -- break here and pop that item
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
return found
|
|
|
|
|
2004-11-29 10:45:41 +05:30
|
|
|
def save(self):
|
|
|
|
"""
|
|
|
|
Attempt saving into XML.
|
|
|
|
The trick is not to fail under any circumstances.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.do_save()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def do_save(self):
|
|
|
|
"""
|
|
|
|
Saves the current GRAMPS RecentFiles collection to the associated file.
|
|
|
|
"""
|
|
|
|
xml_file = file(os.path.expanduser(GRAMPS_FILENAME),'w')
|
2005-12-30 09:27:31 +05:30
|
|
|
if use_lock:
|
|
|
|
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
2004-11-29 10:45:41 +05:30
|
|
|
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
|
|
|
xml_file.write('<RecentFiles>\n')
|
|
|
|
index = 0
|
|
|
|
for item in self.gramps_recent_files:
|
|
|
|
index = index + 1
|
|
|
|
if index > MAX_GRAMPS_ITEMS:
|
|
|
|
break
|
|
|
|
xml_file.write(' <RecentItem>\n')
|
|
|
|
xml_file.write(' <Path>%s</Path>\n' % item.get_path())
|
2007-06-14 11:02:06 +05:30
|
|
|
xml_file.write(' <Name>%s</Name>\n' % item.get_name())
|
2004-11-29 10:45:41 +05:30
|
|
|
xml_file.write(' <Timestamp>%d</Timestamp>\n' % item.get_time())
|
|
|
|
xml_file.write(' </RecentItem>\n')
|
|
|
|
xml_file.write('</RecentFiles>\n')
|
2005-12-30 09:27:31 +05:30
|
|
|
if use_lock:
|
|
|
|
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
2004-11-29 10:45:41 +05:30
|
|
|
xml_file.close()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2007-06-14 11:02:06 +05:30
|
|
|
# RecentParser
|
2004-11-29 10:45:41 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-06-14 11:02:06 +05:30
|
|
|
class RecentParser:
|
2004-11-29 10:45:41 +05:30
|
|
|
"""
|
2007-06-14 11:02:06 +05:30
|
|
|
Parsing class for the RecentFiles collection.
|
2004-11-29 10:45:41 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.recent_files = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
xml_file = open(os.path.expanduser(GRAMPS_FILENAME))
|
2005-12-30 09:27:31 +05:30
|
|
|
if use_lock:
|
|
|
|
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
2004-11-29 10:45:41 +05:30
|
|
|
|
2005-02-19 06:19:49 +05:30
|
|
|
p = ParserCreate()
|
2004-11-29 10:45:41 +05:30
|
|
|
p.StartElementHandler = self.startElement
|
|
|
|
p.EndElementHandler = self.endElement
|
|
|
|
p.CharacterDataHandler = self.characters
|
|
|
|
p.ParseFile(xml_file)
|
|
|
|
|
2005-12-30 09:27:31 +05:30
|
|
|
if use_lock:
|
|
|
|
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
2004-11-29 10:45:41 +05:30
|
|
|
xml_file.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
return self.recent_files
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
self.tlist = []
|
|
|
|
if tag == "RecentItem":
|
2007-06-14 11:02:06 +05:30
|
|
|
self.item = RecentItem()
|
2004-11-29 10:45:41 +05:30
|
|
|
|
|
|
|
def endElement(self,tag):
|
|
|
|
|
|
|
|
text = ''.join(self.tlist)
|
|
|
|
|
|
|
|
if tag == "RecentItem":
|
2007-06-14 11:02:06 +05:30
|
|
|
if os.path.isdir(self.item.get_path()):
|
2006-04-06 22:20:05 +05:30
|
|
|
self.recent_files.append(self.item)
|
2004-11-29 10:45:41 +05:30
|
|
|
elif tag == "Path":
|
|
|
|
self.item.set_path(text)
|
2007-06-14 11:02:06 +05:30
|
|
|
elif tag == "Name":
|
|
|
|
self.item.set_name(text)
|
2004-11-29 10:45:41 +05:30
|
|
|
elif tag == "Timestamp":
|
|
|
|
self.item.set_time(int(text))
|
|
|
|
|
|
|
|
def characters(self, data):
|
|
|
|
self.tlist.append(data)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-11-30 07:46:30 +05:30
|
|
|
# Helper functions
|
2004-11-29 10:45:41 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
def recent_files(filename, name):
|
2004-11-29 10:45:41 +05:30
|
|
|
"""
|
|
|
|
Add an entry to both GNOME and GRAMPS recent-items storages.
|
|
|
|
"""
|
|
|
|
|
|
|
|
the_time = int(time.time())
|
2007-06-14 11:02:06 +05:30
|
|
|
gramps_rf = RecentFiles()
|
|
|
|
gramps_item = RecentItem(
|
2004-11-29 10:45:41 +05:30
|
|
|
p=filename,
|
2007-06-14 11:02:06 +05:30
|
|
|
n=name,
|
2004-11-29 10:45:41 +05:30
|
|
|
t=the_time)
|
|
|
|
gramps_rf.add(gramps_item)
|
|
|
|
gramps_rf.save()
|
|
|
|
|
2004-11-30 07:46:30 +05:30
|
|
|
def remove_filename(filename):
|
2007-06-14 11:02:06 +05:30
|
|
|
gramps_rf = RecentFiles()
|
2004-11-30 07:46:30 +05:30
|
|
|
gramps_rf.remove_filename(filename)
|
|
|
|
gramps_rf.save()
|
2007-12-19 22:10:08 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def rename_filename(filename, new_filename):
|
2007-12-19 22:10:08 +05:30
|
|
|
gramps_rf = RecentFiles()
|
2008-02-24 19:25:55 +05:30
|
|
|
gramps_rf.rename_filename(filename, new_filename)
|
2007-12-19 22:10:08 +05:30
|
|
|
gramps_rf.save()
|
|
|
|
|
|
|
|
def check_if_recent(filename):
|
|
|
|
gramps_rf = RecentFiles()
|
|
|
|
return gramps_rf.check_if_recent(filename)
|
|
|
|
|