2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-12 19:11:54 +05:30
|
|
|
# Copyright (C) 2001-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +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
|
|
|
|
#
|
|
|
|
|
2003-10-18 21:20:16 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-01-10 10:51:32 +05:30
|
|
|
import os
|
2005-02-25 06:43:27 +05:30
|
|
|
import gc
|
2005-04-04 05:57:06 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.gdk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-01-10 10:51:32 +05:30
|
|
|
import RelLib
|
2002-10-20 19:55:16 +05:30
|
|
|
import Utils
|
2005-01-06 22:58:31 +05:30
|
|
|
import GrampsKeys
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
2003-01-10 10:51:32 +05:30
|
|
|
import ImageSelect
|
2005-01-09 07:48:49 +05:30
|
|
|
import ImgManip
|
2002-10-20 19:55:16 +05:30
|
|
|
import RelImage
|
2004-03-22 10:11:35 +05:30
|
|
|
import DisplayModels
|
2004-04-04 10:09:52 +05:30
|
|
|
import GrampsMime
|
2003-05-20 23:25:52 +05:30
|
|
|
from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog
|
2003-01-10 10:51:32 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
column_names = [
|
|
|
|
_('Title'),
|
|
|
|
_('ID'),
|
|
|
|
_('Type'),
|
|
|
|
_('Path'),
|
2004-08-24 09:18:15 +05:30
|
|
|
_('Last Changed'),
|
2005-01-12 19:11:54 +05:30
|
|
|
_('Date'),
|
2004-03-22 10:11:35 +05:30
|
|
|
]
|
|
|
|
|
2005-01-12 19:11:54 +05:30
|
|
|
_HANDLE_COL = len(column_names)
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# MediaView
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class MediaView:
|
2004-02-26 09:04:19 +05:30
|
|
|
def __init__(self,parent,db,glade,update):
|
|
|
|
self.parent = parent
|
2005-04-04 06:41:50 +05:30
|
|
|
self.parent.connect('database-changed',self.change_db)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
|
|
|
self.list = glade.get_widget("media_list")
|
|
|
|
self.mid = glade.get_widget("mid")
|
|
|
|
self.mtype = glade.get_widget("mtype")
|
|
|
|
self.mdesc = glade.get_widget("mdesc")
|
|
|
|
self.mpath = glade.get_widget("mpath")
|
|
|
|
self.mdetails = glade.get_widget("mdetails")
|
|
|
|
self.preview = glade.get_widget("preview")
|
2004-06-03 11:05:30 +05:30
|
|
|
self.topWindow = glade.get_widget("gramps")
|
2004-03-22 10:11:35 +05:30
|
|
|
self.renderer = gtk.CellRendererText()
|
2004-08-19 08:07:35 +05:30
|
|
|
self.model = DisplayModels.MediaModel(self.db)
|
2005-05-24 18:38:06 +05:30
|
|
|
self.sort_col = 0
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.selection = self.list.get_selection()
|
|
|
|
self.list.set_model(self.model)
|
|
|
|
|
2004-12-01 09:45:08 +05:30
|
|
|
DND_TARGETS = [
|
|
|
|
('STRING', 0, 0),
|
|
|
|
('text/plain',0,0),
|
|
|
|
('text/uri-list',0,2),
|
|
|
|
('application/x-rootwin-drop',0,1)]
|
|
|
|
|
|
|
|
self.list.enable_model_drag_source(
|
|
|
|
gtk.gdk.BUTTON1_MASK,
|
|
|
|
DND_TARGETS,
|
|
|
|
gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY
|
|
|
|
)
|
|
|
|
|
|
|
|
self.list.drag_source_set(
|
|
|
|
gtk.gdk.BUTTON1_MASK|gtk.gdk.BUTTON3_MASK,
|
|
|
|
DND_TARGETS,
|
|
|
|
gtk.gdk.ACTION_COPY
|
|
|
|
)
|
|
|
|
|
|
|
|
self.list.enable_model_drag_dest(
|
|
|
|
DND_TARGETS,
|
|
|
|
gtk.gdk.ACTION_DEFAULT
|
|
|
|
)
|
|
|
|
self.list.drag_dest_set(
|
|
|
|
gtk.DEST_DEFAULT_ALL,
|
|
|
|
DND_TARGETS,
|
|
|
|
gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE
|
|
|
|
)
|
|
|
|
|
|
|
|
self.list.connect("drag-data-received", self.on_drag_data_received)
|
|
|
|
self.list.connect("drag-data-get", self.on_drag_data_get)
|
|
|
|
self.list.connect("drag-begin", self.on_drag_begin)
|
|
|
|
self.list.connect("drag-drop", self.on_drag_drop)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.list.connect('button-press-event',self.on_button_press_event)
|
2004-02-15 08:54:12 +05:30
|
|
|
self.list.connect('key-press-event',self.key_press)
|
2004-12-01 09:45:08 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.selection.connect('changed',self.on_select_row)
|
2004-12-01 09:45:08 +05:30
|
|
|
self.update = update
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns = []
|
|
|
|
self.build_columns()
|
|
|
|
self.build_tree()
|
|
|
|
|
2005-05-24 18:38:06 +05:30
|
|
|
def column_clicked(self,obj,data):
|
|
|
|
if self.sort_col != data:
|
|
|
|
order = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING
|
|
|
|
or self.columns[data].get_sort_indicator() == False):
|
|
|
|
order = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
order = gtk.SORT_DESCENDING
|
|
|
|
self.sort_col = data
|
|
|
|
handle = self.first_selected()
|
|
|
|
self.model = DisplayModels.MediaModel(self.parent.db,
|
|
|
|
self.sort_col,order)
|
|
|
|
self.list.set_model(self.model)
|
|
|
|
|
|
|
|
colmap = self.parent.db.get_place_column_order()
|
|
|
|
|
|
|
|
if handle:
|
|
|
|
path = self.model.on_get_path(handle)
|
|
|
|
self.selection.select_path(path)
|
|
|
|
self.list.scroll_to_cell(path,None,1,0.5,0)
|
|
|
|
for i in range(0,len(self.columns)):
|
|
|
|
self.columns[i].set_sort_indicator(i==colmap[data][1]-1)
|
|
|
|
self.columns[self.sort_col].set_sort_order(order)
|
|
|
|
|
|
|
|
def first_selected(self):
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
if mlist:
|
|
|
|
return mlist[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def blist(self,store,path,iter,list):
|
|
|
|
handle = store.get_value(iter,_HANDLE_COL)
|
|
|
|
list.append(handle)
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def build_columns(self):
|
|
|
|
for column in self.columns:
|
|
|
|
self.list.remove_column(column)
|
|
|
|
|
|
|
|
column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0)
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_resizable(True)
|
2005-05-24 18:38:06 +05:30
|
|
|
column.connect('clicked',self.column_clicked,0)
|
|
|
|
column.set_clickable(True)
|
2004-03-22 10:11:35 +05:30
|
|
|
column.set_min_width(225)
|
|
|
|
self.list.append_column(column)
|
|
|
|
self.columns = [column]
|
|
|
|
|
|
|
|
index = 1
|
|
|
|
for pair in self.parent.db.get_media_column_order():
|
|
|
|
if not pair[0]:
|
|
|
|
continue
|
|
|
|
name = column_names[pair[1]]
|
|
|
|
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_resizable(True)
|
2004-03-22 10:11:35 +05:30
|
|
|
column.set_min_width(75)
|
2005-05-24 18:38:06 +05:30
|
|
|
column.set_clickable(True)
|
|
|
|
column.connect('clicked',self.column_clicked,index)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns.append(column)
|
|
|
|
self.list.append_column(column)
|
|
|
|
index += 1
|
|
|
|
|
2005-04-04 05:57:06 +05:30
|
|
|
def media_add(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.add_row_by_handle(handle)
|
|
|
|
|
|
|
|
def media_update(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.update_row_by_handle(handle)
|
|
|
|
|
|
|
|
def media_delete(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.delete_row_by_handle(handle)
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def change_db(self,db):
|
2005-04-04 05:57:06 +05:30
|
|
|
db.connect('media-add', self.media_add)
|
|
|
|
db.connect('media-update', self.media_update)
|
|
|
|
db.connect('media-delete', self.media_delete)
|
|
|
|
db.connect('media-rebuild',self.build_tree)
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
self.db = db
|
|
|
|
self.build_columns()
|
|
|
|
self.build_tree()
|
2003-04-04 11:18:25 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def build_tree(self):
|
2004-08-31 09:21:05 +05:30
|
|
|
self.model = DisplayModels.MediaModel(self.parent.db)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.list.set_model(self.model)
|
|
|
|
self.selection = self.list.get_selection()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_select_row(self,obj):
|
|
|
|
fexists = 1
|
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if not node:
|
2002-10-27 09:13:12 +05:30
|
|
|
return
|
2004-08-24 23:35:18 +05:30
|
|
|
|
2005-01-12 19:11:54 +05:30
|
|
|
handle = store.get_value(node,_HANDLE_COL)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
mobj = self.db.get_object_from_handle(handle)
|
|
|
|
mtype = mobj.get_mime_type()
|
2004-10-24 23:06:33 +05:30
|
|
|
path = mobj.get_path()
|
2005-02-16 11:11:33 +05:30
|
|
|
if mtype:
|
|
|
|
type_name = Utils.get_mime_description(mtype)
|
2005-02-24 05:55:34 +05:30
|
|
|
if mtype[0:5] == "image":
|
|
|
|
image = ImgManip.get_thumbnail_image(path)
|
2005-02-16 11:11:33 +05:30
|
|
|
else:
|
2005-02-25 06:46:18 +05:30
|
|
|
image = Utils.find_mime_type_pixbuf(mtype)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-02-25 06:46:18 +05:30
|
|
|
image = Utils.find_mime_type_pixbuf('text/plain')
|
2005-02-16 11:11:33 +05:30
|
|
|
type_name = _('Note')
|
2005-02-25 06:46:18 +05:30
|
|
|
self.preview.set_from_pixbuf(image)
|
2005-04-04 05:57:06 +05:30
|
|
|
del image
|
2005-02-25 06:43:27 +05:30
|
|
|
gc.collect()
|
|
|
|
|
2004-08-24 23:35:18 +05:30
|
|
|
self.mid.set_text(mobj.get_gramps_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
self.mtype.set_text(type_name)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.mdesc.set_text(mobj.get_description())
|
2002-10-20 19:55:16 +05:30
|
|
|
if len(path) == 0 or fexists == 0:
|
|
|
|
self.mpath.set_text(_("The file no longer exists"))
|
|
|
|
else:
|
2005-02-16 11:11:33 +05:30
|
|
|
self.mpath.set_text(path)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.mdetails.set_text(Utils.get_detail_text(mobj,0))
|
|
|
|
|
|
|
|
def on_button_press_event(self,obj,event):
|
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2003-10-18 21:20:16 +05:30
|
|
|
self.on_edit_clicked(obj)
|
|
|
|
return 1
|
2002-10-20 19:55:16 +05:30
|
|
|
elif event.button == 3:
|
2003-10-22 04:01:37 +05:30
|
|
|
self.build_context_menu(event)
|
2003-10-18 21:20:16 +05:30
|
|
|
return 1
|
|
|
|
return 0
|
2004-02-15 08:54:12 +05:30
|
|
|
|
|
|
|
def key_press(self,obj,event):
|
|
|
|
if event.keyval == gtk.gdk.keyval_from_name("Return") \
|
|
|
|
and not event.state:
|
|
|
|
self.on_edit_clicked(obj)
|
|
|
|
return 1
|
|
|
|
return 0
|
2003-10-18 21:20:16 +05:30
|
|
|
|
2003-10-22 04:01:37 +05:30
|
|
|
def build_context_menu(self,event):
|
2003-10-18 21:20:16 +05:30
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.set_title(_("Media Object"))
|
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if node:
|
2005-01-12 19:11:54 +05:30
|
|
|
handle = store.get_value(node,_HANDLE_COL)
|
2004-08-20 17:41:56 +05:30
|
|
|
obj = self.db.get_object_from_handle(handle)
|
|
|
|
self.obj = obj
|
|
|
|
mime_type = obj.get_mime_type()
|
2004-04-04 10:09:52 +05:30
|
|
|
|
2004-02-27 09:37:23 +05:30
|
|
|
Utils.add_menuitem(menu,_("View in the default viewer"),None,
|
|
|
|
self.popup_view_photo)
|
2004-04-04 10:09:52 +05:30
|
|
|
|
2005-02-16 11:11:33 +05:30
|
|
|
if mime_type and mime_type[0:5] == "image":
|
2004-02-27 09:37:23 +05:30
|
|
|
Utils.add_menuitem(menu,_("Edit with the GIMP"),
|
2002-10-20 19:55:16 +05:30
|
|
|
None,self.popup_edit_photo)
|
2003-10-18 21:20:16 +05:30
|
|
|
item = gtk.MenuItem()
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
|
|
|
sel_sensitivity = 1
|
|
|
|
else:
|
|
|
|
sel_sensitivity = 0
|
|
|
|
|
|
|
|
entries = [
|
|
|
|
(gtk.STOCK_ADD, self.on_add_clicked,1),
|
|
|
|
(gtk.STOCK_REMOVE, self.on_delete_clicked,sel_sensitivity),
|
|
|
|
(_("Edit properties"), self.on_edit_clicked,sel_sensitivity),
|
|
|
|
]
|
|
|
|
|
|
|
|
for stock_id,callback,sensitivity in entries:
|
|
|
|
item = gtk.ImageMenuItem(stock_id)
|
|
|
|
if callback:
|
|
|
|
item.connect("activate",callback)
|
|
|
|
item.set_sensitive(sensitivity)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
2003-10-22 04:01:37 +05:30
|
|
|
menu.popup(None,None,None,event.button,event.time)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def popup_view_photo(self, obj):
|
|
|
|
Utils.view_photo(self.obj)
|
|
|
|
|
|
|
|
def popup_edit_photo(self, obj):
|
|
|
|
if os.fork() == 0:
|
2004-02-14 11:10:30 +05:30
|
|
|
os.execvp(const.editor,[const.editor, self.obj.get_path()])
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def popup_change_description(self, obj):
|
2005-04-04 05:57:06 +05:30
|
|
|
ImageSelect.GlobalMediaProperties(self.db,self.obj,self,self.topWindow)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-12-11 10:48:47 +05:30
|
|
|
def on_add_clicked(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Add a new media object to the media list"""
|
|
|
|
import AddMedia
|
2005-04-04 05:57:06 +05:30
|
|
|
am = AddMedia.AddMediaObject(self.db)
|
2003-09-10 19:08:02 +05:30
|
|
|
am.run()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-12-11 10:48:47 +05:30
|
|
|
def on_edit_clicked(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Edit the properties of an existing media object in the media list"""
|
2002-12-11 10:48:47 +05:30
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
list_store, node = self.selection.get_selected()
|
|
|
|
if node:
|
2005-01-12 19:11:54 +05:30
|
|
|
handle = list_store.get_value(node,_HANDLE_COL)
|
2004-08-20 17:41:56 +05:30
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2005-02-16 11:11:33 +05:30
|
|
|
if obj.get_mime_type():
|
2005-04-04 05:57:06 +05:30
|
|
|
ImageSelect.GlobalMediaProperties(self.db,obj,self,self.topWindow)
|
2005-02-16 11:11:33 +05:30
|
|
|
else:
|
|
|
|
import NoteEdit
|
|
|
|
NoteEdit.NoteEditor(obj,self.parent,self.topWindow,
|
|
|
|
self.note_callback)
|
|
|
|
|
|
|
|
def note_callback(self,data):
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.commit_media_object(data,trans)
|
|
|
|
self.db.transaction_commit(trans,_("Edit Media Object"))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_delete_clicked(self,obj):
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if not node:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2002-12-11 10:48:47 +05:30
|
|
|
|
2005-01-12 19:11:54 +05:30
|
|
|
handle = store.get_value(node,_HANDLE_COL)
|
2005-03-12 06:14:11 +05:30
|
|
|
the_lists = Utils.get_media_referents(handle,self.db)
|
|
|
|
|
2005-04-04 05:57:06 +05:30
|
|
|
ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists)
|
2005-03-12 06:14:11 +05:30
|
|
|
if filter(None,the_lists): # quick test for non-emptiness
|
|
|
|
msg = _('This media object is currently being used. '
|
|
|
|
'If you delete this object, it will be removed from '
|
|
|
|
'the database and from all records that reference it.')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-03-12 06:14:11 +05:30
|
|
|
msg = _('Deleting media object will remove it from the database.')
|
|
|
|
|
|
|
|
msg = "%s %s" % (msg,Utils.data_recover_msg)
|
|
|
|
QuestionDialog(_('Delete Media Object?'),msg,
|
|
|
|
_('_Delete Media Object'),ans.query_response)
|
2003-05-17 08:50:50 +05:30
|
|
|
|
2004-12-01 09:45:08 +05:30
|
|
|
def on_drag_drop(self, tree, context, x, y, time):
|
|
|
|
self.list.emit_stop_by_name('drag-drop')
|
|
|
|
return 1
|
|
|
|
|
2003-05-17 08:50:50 +05:30
|
|
|
def on_drag_begin(self,obj,context):
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if not node:
|
2003-05-17 08:50:50 +05:30
|
|
|
return
|
|
|
|
if (const.dnd_images):
|
2005-01-12 19:11:54 +05:30
|
|
|
handle = store.get_value(node,_HANDLE_COL)
|
2004-11-29 08:54:02 +05:30
|
|
|
obj = self.db.get_object_from_handle(handle)
|
2005-02-16 11:11:33 +05:30
|
|
|
if obj.get_path():
|
|
|
|
image = ImgManip.get_thumbnail_image(obj.get_path())
|
|
|
|
context.set_icon_pixbuf(image,0,0)
|
2003-05-17 08:50:50 +05:30
|
|
|
|
2004-12-01 09:45:08 +05:30
|
|
|
def on_drag_data_get(self, w, context, selection_data, info, time):
|
2002-10-20 19:55:16 +05:30
|
|
|
if info == 1:
|
|
|
|
return
|
2003-05-17 08:50:50 +05:30
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if not node:
|
2003-05-17 08:50:50 +05:30
|
|
|
return
|
2005-04-05 01:23:21 +05:30
|
|
|
handle = store.get_value(node,_HANDLE_COL)
|
2005-02-25 06:43:27 +05:30
|
|
|
selection_data.set(selection_data.target, 8, handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_drag_data_received(self,w, context, x, y, data, info, time):
|
|
|
|
import urlparse
|
2004-12-01 09:45:08 +05:30
|
|
|
|
|
|
|
self.list.emit_stop_by_name('drag-data-received')
|
2002-10-20 19:55:16 +05:30
|
|
|
if data and data.format == 8:
|
2005-04-04 05:57:06 +05:30
|
|
|
d = data.data.replace('\0',' ').strip()
|
2004-08-20 17:41:56 +05:30
|
|
|
protocol,site,name, j,k,l = urlparse.urlparse(d)
|
2002-10-20 19:55:16 +05:30
|
|
|
if protocol == "file":
|
2004-04-04 10:09:52 +05:30
|
|
|
mime = GrampsMime.get_type(name)
|
2004-02-21 11:41:59 +05:30
|
|
|
photo = RelLib.MediaObject()
|
2004-02-14 11:10:30 +05:30
|
|
|
photo.set_path(name)
|
|
|
|
photo.set_mime_type(mime)
|
2002-10-20 19:55:16 +05:30
|
|
|
description = os.path.basename(name)
|
2004-02-14 11:10:30 +05:30
|
|
|
photo.set_description(description)
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2004-03-30 10:20:24 +05:30
|
|
|
self.db.add_object(photo,trans)
|
|
|
|
|
|
|
|
self.db.commit_media_object(photo,trans)
|
2004-08-13 10:04:07 +05:30
|
|
|
self.db.transaction_commit(trans,_("Add Media Object"))
|
2004-12-01 09:45:08 +05:30
|
|
|
self.build_tree()
|
2005-01-06 22:58:31 +05:30
|
|
|
if GrampsKeys.get_media_global():
|
2004-08-31 09:21:05 +05:30
|
|
|
ImageSelect.GlobalMediaProperties(self.db,photo,
|
|
|
|
self,self.topWindow)
|
2002-10-20 19:55:16 +05:30
|
|
|
elif protocol != "":
|
|
|
|
import urllib
|
|
|
|
u = urllib.URLopener()
|
|
|
|
try:
|
|
|
|
tfile,headers = u.retrieve(d)
|
|
|
|
except IOError, msg:
|
2003-03-21 10:12:12 +05:30
|
|
|
ErrorDialog(_('Image import failed'),str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2004-04-04 10:09:52 +05:30
|
|
|
mime = GrampsMime.get_type(tfile)
|
2004-02-21 11:41:59 +05:30
|
|
|
photo = RelLib.MediaObject()
|
2004-02-14 11:10:30 +05:30
|
|
|
photo.set_mime_type(mime)
|
|
|
|
photo.set_description(d)
|
|
|
|
photo.set_path(tfile)
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2004-03-30 10:20:24 +05:30
|
|
|
self.db.add_object(photo,trans)
|
2004-02-21 11:41:59 +05:30
|
|
|
oref = RelLib.MediaRef()
|
2004-07-28 07:59:07 +05:30
|
|
|
oref.set_reference_handle(photo.get_handle())
|
2004-03-30 10:20:24 +05:30
|
|
|
|
|
|
|
self.db.commit_media_object(photo,trans)
|
2004-08-13 10:04:07 +05:30
|
|
|
self.db.transaction_commit(trans,_("Add Media Object"))
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2005-01-06 22:58:31 +05:30
|
|
|
if GrampsKeys.get_media_global():
|
2005-04-04 05:57:06 +05:30
|
|
|
ImageSelect.GlobalMediaProperties(self.db,photo,
|
2004-06-03 11:05:30 +05:30
|
|
|
self,self.topWindow)
|