* src/DbManager.py: Add support for Thunar, which stores the DND
information in a different area (and probably a more correct area) than Nautilus. 2007-07-08 Don Allingham <don@gramps-project.org> svn: r8709
This commit is contained in:
parent
8f445b7114
commit
0fa16f7bd2
@ -1,3 +1,8 @@
|
|||||||
|
2007-07-08 Don Allingham <don@gramps-project.org>
|
||||||
|
* src/DbManager.py: Add support for Thunar, which stores the DND
|
||||||
|
information in a different area (and probably a more correct area) than
|
||||||
|
Nautilus.
|
||||||
|
|
||||||
2007-07-08 Don Allingham <don@gramps-project.org>
|
2007-07-08 Don Allingham <don@gramps-project.org>
|
||||||
* src/DbManager.py: handle drag-n-drop files in DbManager. Dragging an
|
* src/DbManager.py: handle drag-n-drop files in DbManager. Dragging an
|
||||||
XML or GEDCOM file into the DbManager will create a new database and import
|
XML or GEDCOM file into the DbManager will create a new database and import
|
||||||
|
@ -33,7 +33,6 @@ __revision__ = "$Revision: 8197 $"
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import Mime
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
@ -70,6 +69,11 @@ import QuestionDialog
|
|||||||
import GrampsDb
|
import GrampsDb
|
||||||
import GrampsDbUtils
|
import GrampsDbUtils
|
||||||
import Config
|
import Config
|
||||||
|
import Mime
|
||||||
|
|
||||||
|
IMPORT_TYPES = (const.app_gramps_xml, const.app_gedcom,
|
||||||
|
const.app_gramps_package, const.app_geneweb,
|
||||||
|
const.app_gramps)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -151,11 +155,10 @@ class DbManager:
|
|||||||
|
|
||||||
self.top.drag_dest_set(
|
self.top.drag_dest_set(
|
||||||
gtk.DEST_DEFAULT_ALL,
|
gtk.DEST_DEFAULT_ALL,
|
||||||
(('application/x-gramps-xml', 0, 1),
|
(('text/plain', 0, 1),
|
||||||
('application/x-gedcom', 0, 2),
|
('text/uri-list', 0, 2)),
|
||||||
('text/plain', 0, 3)),
|
|
||||||
ACTION_COPY)
|
ACTION_COPY)
|
||||||
self.top.connect('drag_data_received', self.drag_data_received)
|
self.top.connect('drag_data_received', self.__drag_data_received)
|
||||||
|
|
||||||
def __button_press(self, obj, event):
|
def __button_press(self, obj, event):
|
||||||
"""
|
"""
|
||||||
@ -642,16 +645,44 @@ class DbManager:
|
|||||||
start_editing=True)
|
start_editing=True)
|
||||||
return new_path
|
return new_path
|
||||||
|
|
||||||
def drag_data_received(self, widget, context, x, y, selection, info, time):
|
def __drag_data_received(self, widget, context, xpos, ypos, selection,
|
||||||
drag_value = selection.get_text().strip()
|
info, rtime):
|
||||||
|
"""
|
||||||
|
Handle the reception of drag data
|
||||||
|
"""
|
||||||
|
|
||||||
|
# The selection object contains the appropriate information.
|
||||||
|
# Unfortunately, not all file managers work the same. Nautilus
|
||||||
|
# stores the file name as the text item in selection, while
|
||||||
|
# thunar holds it in uris.
|
||||||
|
|
||||||
|
# Check for Thunar
|
||||||
|
uris = selection.get_uris()
|
||||||
|
if uris: # Thunar
|
||||||
|
drag_value = uris[0]
|
||||||
|
elif selection.get_text(): # Nautilus
|
||||||
|
drag_value = selection.get_text().strip()
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# we are only interested in this if it is a file:// URL.
|
||||||
if drag_value[0:7] == "file://":
|
if drag_value[0:7] == "file://":
|
||||||
|
|
||||||
|
# deterimine the mime type. If it is one that we are interested in,
|
||||||
|
# we process it
|
||||||
filetype = Mime.get_type(drag_value)
|
filetype = Mime.get_type(drag_value)
|
||||||
if filetype in (const.app_gramps_xml, const.app_gedcom):
|
if filetype in IMPORT_TYPES:
|
||||||
|
|
||||||
|
# get the name of the database from the filename of the file
|
||||||
(name, ext) = os.path.splitext(os.path.basename(drag_value))
|
(name, ext) = os.path.splitext(os.path.basename(drag_value))
|
||||||
|
|
||||||
|
# create the database
|
||||||
new_path = self.__create_new_db(name)
|
new_path = self.__create_new_db(name)
|
||||||
trans = Config.TRANSACTIONS
|
trans = Config.TRANSACTIONS
|
||||||
dbtype = 'x-directory/normal'
|
dbtype = 'x-directory/normal'
|
||||||
|
|
||||||
|
# get the import function using the filetype, but create a db
|
||||||
|
# based on the DBDir
|
||||||
self.__start_cursor(_("Importing data..."))
|
self.__start_cursor(_("Importing data..."))
|
||||||
dbase = GrampsDb.gramps_db_factory(dbtype)(trans)
|
dbase = GrampsDb.gramps_db_factory(dbtype)(trans)
|
||||||
dbase.load(new_path, None)
|
dbase.load(new_path, None)
|
||||||
@ -659,6 +690,7 @@ class DbManager:
|
|||||||
rdr = GrampsDbUtils.gramps_db_reader_factory(filetype)
|
rdr = GrampsDbUtils.gramps_db_reader_factory(filetype)
|
||||||
rdr(dbase, drag_value[7:], None)
|
rdr(dbase, drag_value[7:], None)
|
||||||
|
|
||||||
|
# finish up
|
||||||
self.__end_cursor()
|
self.__end_cursor()
|
||||||
dbase.close()
|
dbase.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user