diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index f2ceb769a..6cc6d571a 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,12 @@ +2004-06-23 Alex Roitman + * src/ArgHandler.py (handle_args): Add import callback call. + * src/gramps_main.py: Use open filters, mime types, and handlers + from import plugins. + * src/Plugins.py: Change import plugin registration. + * src/ReadXML.py: Change registration. + * src/plugins/ReadGedcom.py: Change registration. + * src/plugins/ReadPkg.py: Rewrite and change registration. + 2004-06-22 Don Allingham * src/EditPerson,py: allow reordering of event columns * src/TransTable.py: allow to be initialized with a list instead of a map diff --git a/gramps2/src/ArgHandler.py b/gramps2/src/ArgHandler.py index 89a960545..78034d8ff 100644 --- a/gramps2/src/ArgHandler.py +++ b/gramps2/src/ArgHandler.py @@ -282,6 +282,9 @@ class ArgHandler: os.remove(self.imp_db_path) print "Exiting." os._exit(0) + + if self.imports: + self.parent.import_tool_callback() elif GrampsCfg.lastfile and GrampsCfg.autoload: if self.parent.auto_save_load(GrampsCfg.lastfile) == 0: DbPrompter.DbPrompter(self.parent,0,self.parent.topWindow) @@ -343,7 +346,7 @@ class ArgHandler: print "Error extracting into %s" % tmpdir_path os._exit(1) - dbname = os.path.join(tmpdir_path,const.xmlFile) + dbname = os.path.join(tmpdir_path,const.xmlFile) try: ReadXML.importData(self.parent.db,dbname,None) diff --git a/gramps2/src/Plugins.py b/gramps2/src/Plugins.py index 25be0cea9..09866a915 100644 --- a/gramps2/src/Plugins.py +++ b/gramps2/src/Plugins.py @@ -464,9 +464,14 @@ def register_export(task, name): """Register an export filter, taking the task and name""" _exports.append((task, name)) -def register_import(task, name): - """Register an import filter, taking the task and name""" - _imports.append((task, name)) +#def register_import(task, name): +# """Register an import filter, taking the task and name""" +# _imports.append((task, name)) + +def register_import(task, ffilter, mime=None): + """Register an import filter, taking the task and file filter""" + if mime: + _imports.append((task, ffilter, mime)) def register_report(task, name, category=_("Uncategorized"), diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index b87df3843..9f6575df4 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -30,6 +30,7 @@ import os import gtk import shutil import xml.parsers.expat +from gettext import gettext as _ #------------------------------------------------------------------------- # @@ -37,7 +38,6 @@ import xml.parsers.expat # #------------------------------------------------------------------------- from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog -from gettext import gettext as _ import Calendar import Date import GrampsMime @@ -61,7 +61,7 @@ except: # Must takes care of renaming media files according to their new IDs. # #------------------------------------------------------------------------- -def importData(database, filename, callback,cl=0): +def importData(database, filename, callback=None,cl=0): filename = os.path.normpath(filename) basefile = os.path.dirname(filename) @@ -1159,3 +1159,15 @@ def build_place_title(loc): value = append_value(value,country) return value +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +_mime_type = 'data.gramps' +_filter = gtk.FileFilter() +_filter.set_name(_('GRAMPS XML databases')) +_filter.add_pattern(_mime_type) + +from Plugins import register_import +register_import(importData,_filter,_mime_type) diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 71ef747eb..d3373f73f 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1466,23 +1466,28 @@ class Gramps: def on_open_activate(self,obj): choose = gtk.FileChooserDialog('Open GRAMPS database', - None, + self.topWindow, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) + # Always add automatic (macth all files) filter filter = gtk.FileFilter() - filter.set_name(_('GRAMPS databases')) - filter.add_pattern('*.grdb') - choose.add_filter(filter) - - filter = gtk.FileFilter() - filter.set_name(_('All files')) + filter.set_name(_('Automatic')) filter.add_pattern('*') choose.add_filter(filter) + # Always add native format filter + filter = gtk.FileFilter() + filter.set_name(_('GRAMPS databases')) + filter.add_mime_type('application/x-gramps') + choose.add_filter(filter) + + for (importData,filter,mime_type) in Plugins._imports: + choose.add_filter(filter) + if GrampsCfg.lastfile: choose.set_filename(GrampsCfg.lastfile) @@ -1491,8 +1496,28 @@ class Gramps: filename = choose.get_filename() filename = os.path.normpath(os.path.abspath(filename)) self.clear_database() - if self.auto_save_load(filename) == 0: - DbPrompter.DbPrompter(self,0,self.topWindow) + filetype = gnome.vfs.get_mime_type(filename) + (junk,the_file) = os.path.split(filename) + + if filetype == 'application/x-gramps': + if self.auto_save_load(filename) == 0: + DbPrompter.DbPrompter(self,0,self.topWindow) + else: + opened = 0 + for (importData,filter,mime_type) in Plugins._imports: + if filetype == mime_type or the_file == mime_type: + OkDialog( _("Opening non-native format"), + _("New gramps database has to be set up when opening non-native formats. The following dialog will let you select the new database."), + self.topWindow) + DbPrompter.DbPrompter(self,1,self.topWindow,filename) + print "filename:", filename + importData(self.db,filename) + self.import_tool_callback() + opened = 1 + break + if not opened: + ErrorDialog( _("Could not open file: %s") % filename, + _('The type "%s" is not in the list of known file types') % filetype ) choose.destroy() def on_revert_activate(self,obj): diff --git a/gramps2/src/plugins/ReadGedcom.py b/gramps2/src/plugins/ReadGedcom.py index bf6bd4b26..eff9bb6ec 100644 --- a/gramps2/src/plugins/ReadGedcom.py +++ b/gramps2/src/plugins/ReadGedcom.py @@ -1801,11 +1801,17 @@ def readData(database,active_person,cb): DisplayTrace.DisplayTrace() else: choose.destroy() - + + +_mime_type = 'application/x-gedcom' +_filter = gtk.FileFilter() +_filter.set_name(_('GEDCOM files')) +_filter.add_mime_type(_mime_type) + #------------------------------------------------------------------------- # # # #------------------------------------------------------------------------- from Plugins import register_import -register_import(readData,_title_string) +register_import(importData,_filter,_mime_type) diff --git a/gramps2/src/plugins/ReadPkg.py b/gramps2/src/plugins/ReadPkg.py index 44e7dd682..c03d1850b 100644 --- a/gramps2/src/plugins/ReadPkg.py +++ b/gramps2/src/plugins/ReadPkg.py @@ -41,49 +41,16 @@ _title_string = _("GRAMPS package") # # #------------------------------------------------------------------------- -def readData(database,active_person,cb): - ReadPkg(database,active_person,cb) +#def readData(database,active_person,cb): +# ReadPkg(database,active_person,cb) #------------------------------------------------------------------------- # # # #------------------------------------------------------------------------- -class ReadPkg: - def __init__(self,database,active_person,cb): - self.db = database - self.callback = cb - - self.top = gtk.FileSelection("%s - GRAMPS" % _title_string) - self.top.hide_fileop_buttons() - self.top.ok_button.connect('clicked', self.on_ok_clicked) - self.top.cancel_button.connect('clicked', self.close_window) - self.top.show() - - def close_window(self,obj): - self.top.destroy() - - def show_display(self): - self.window = gtk.Window() - self.window.set_title(_title_string) - vbox = gtk.VBox() - self.window.add(vbox) - label = gtk.Label(_title_string) - vbox.add(label) - adj = gtk.Adjustment(lower=0,upper=100) - self.progress_bar = gtk.ProgressBar(adj) - vbox.add(self.progress_bar) - self.window.show_all() - - def on_ok_clicked(self,obj): - - name = self.top.get_filename() - if name == "": - return - - Utils.destroy_passed_object(self.top) - self.show_display() - +def impData(database, name,cb=None,cl=0): + print "name1:", name # Create tempdir, if it does not exist, then check for writability tmpdir_path = os.path.expanduser("~/.gramps/tmp" ) if not os.path.isdir(tmpdir_path): @@ -101,18 +68,21 @@ class ReadPkg: for filename in files: os.remove( os.path.join(tmpdir_path,filename) ) + print "name2:", name try: t = TarFile.ReadTarFile(name,tmpdir_path) t.extract() t.close() except: + print "name3:", name + print tmpdir_path ErrorDialog(_("Error extracting into %s") % tmpdir_path ) return dbname = os.path.join(tmpdir_path,const.xmlFile) try: - importData(self.db,dbname,self.progress) + importData(database,dbname,cb) except: import DisplayTrace DisplayTrace.DisplayTrace() @@ -124,19 +94,101 @@ class ReadPkg: os.rmdir(tmpdir_path) - self.window.destroy() - self.callback() - - def progress(self,val): - self.progress_bar.set_fraction(val) - while gtk.events_pending(): - gtk.mainiteration() - +#class ReadPkg: +# def __init__(self,database,active_person,cb): +# self.db = database +# self.callback = cb +# +# self.top = gtk.FileSelection("%s - GRAMPS" % _title_string) +# self.top.hide_fileop_buttons() +# self.top.ok_button.connect('clicked', self.on_ok_clicked) +# self.top.cancel_button.connect('clicked', self.close_window) +# self.top.show() +# +# def close_window(self,obj): +# self.top.destroy() +# +# def show_display(self): +# self.window = gtk.Window() +# self.window.set_title(_title_string) +# vbox = gtk.VBox() +# self.window.add(vbox) +# label = gtk.Label(_title_string) +# vbox.add(label) +# adj = gtk.Adjustment(lower=0,upper=100) +# self.progress_bar = gtk.ProgressBar(adj) +# vbox.add(self.progress_bar) +# self.window.show_all() +# +# def on_ok_clicked(self,obj): +# +# name = self.top.get_filename() +# if name == "": +# return +# +# Utils.destroy_passed_object(self.top) +# self.show_display() +# +# # Create tempdir, if it does not exist, then check for writability +# tmpdir_path = os.path.expanduser("~/.gramps/tmp" ) +# if not os.path.isdir(tmpdir_path): +# try: +# os.mkdir(tmpdir_path,0700) +# except: +# ErrorDialog( _("Could not create temporary directory %s") % +# tmpdir_path ) +# return +# elif not os.access(tmpdir_path,os.W_OK): +# ErrorDialog( _("Temporary directory %s is not writable") % tmpdir_path ) +# return +# else: # tempdir exists and writable -- clean it up if not empty +# files = os.listdir(tmpdir_path) ; +# for filename in files: +# os.remove( os.path.join(tmpdir_path,filename) ) +# +# try: +# t = TarFile.ReadTarFile(name,tmpdir_path) +# t.extract() +# except: +# ErrorDialog(_("Error extracting into %s") % tmpdir_path ) +# return +# +# dbname = os.path.join(tmpdir_path,const.xmlFile) +# +# try: +# importData(self.db,dbname,self.progress) +# except: +# import DisplayTrace +# DisplayTrace.DisplayTrace() +# +# +# +# +# # Clean up tempdir after ourselves +# files = os.listdir(tmpdir_path) +# for filename in files: +# os.remove(os.path.join(tmpdir_path,filename)) +# +# os.rmdir(tmpdir_path) +# +# self.window.destroy() +# self.callback() +# +# def progress(self,val): +# self.progress_bar.set_fraction(val) +# while gtk.events_pending(): +# gtk.mainiteration() +# #------------------------------------------------------------------------ # # Register with the plugin system # #------------------------------------------------------------------------ -from Plugins import register_import +_mime_type = 'application/x-gramps-package' +_filter = gtk.FileFilter() +_filter.set_name(_('GRAMPS package')) +_filter.add_mime_type(_mime_type) -register_import(readData,_title_string) +from Plugins import register_import +register_import(impData,_filter,_mime_type) +#register_import(readData,_title_string)