2002-10-20 19:55:16 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-05-02 11:20:46 +05:30
|
|
|
# Copyright (C) 2001-2006 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$
|
|
|
|
|
2006-05-17 11:43:37 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gettext import gettext as _
|
2006-08-12 03:44:18 +05:30
|
|
|
import urlparse
|
|
|
|
import os
|
2006-05-17 11:43:37 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-14 10:01:29 +05:30
|
|
|
import PageView
|
|
|
|
import DisplayModels
|
2005-01-09 07:48:49 +05:30
|
|
|
import ImgManip
|
2005-08-14 10:01:29 +05:30
|
|
|
import const
|
2006-08-10 06:12:44 +05:30
|
|
|
import Config
|
2005-08-14 10:01:29 +05:30
|
|
|
import Utils
|
2006-04-27 03:18:13 +05:30
|
|
|
import Bookmarks
|
2006-08-12 03:44:18 +05:30
|
|
|
import Mime
|
|
|
|
import RelLib
|
|
|
|
|
2006-05-11 06:03:17 +05:30
|
|
|
from Editors import EditMedia
|
|
|
|
import Errors
|
2006-07-03 09:55:33 +05:30
|
|
|
from QuestionDialog import QuestionDialog
|
2006-08-10 06:12:44 +05:30
|
|
|
from Filters.SideBar import MediaSidebarFilter
|
2006-08-12 03:44:18 +05:30
|
|
|
from DdTargets import DdTargets
|
2005-08-14 10:01:29 +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
|
|
|
]
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# MediaView
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-08-14 10:01:29 +05:30
|
|
|
class MediaView(PageView.ListView):
|
2006-05-08 06:45:19 +05:30
|
|
|
|
|
|
|
ADD_MSG = _("Add a new media object")
|
|
|
|
EDIT_MSG = _("Edit the selected media object")
|
|
|
|
DEL_MSG = _("Delete the selected media object")
|
|
|
|
|
2006-08-12 03:44:18 +05:30
|
|
|
_DND_TYPE = DdTargets.URI_LIST
|
|
|
|
|
2005-08-14 10:01:29 +05:30
|
|
|
def __init__(self,dbstate,uistate):
|
|
|
|
|
|
|
|
signal_map = {
|
|
|
|
'media-add' : self.row_add,
|
|
|
|
'media-update' : self.row_update,
|
|
|
|
'media-delete' : self.row_delete,
|
|
|
|
'media-rebuild' : self.build_tree,
|
|
|
|
}
|
|
|
|
|
2006-04-23 03:39:16 +05:30
|
|
|
PageView.ListView.__init__(
|
|
|
|
self, _('Media'), dbstate, uistate,
|
|
|
|
column_names,len(column_names), DisplayModels.MediaModel,
|
2006-04-27 03:18:13 +05:30
|
|
|
signal_map, dbstate.db.get_media_bookmarks(),
|
2006-08-10 06:12:44 +05:30
|
|
|
Bookmarks.MediaBookmarks,filter_class=MediaSidebarFilter)
|
|
|
|
|
|
|
|
Config.client.notify_add("/apps/gramps/interface/filter",
|
|
|
|
self.filter_toggle)
|
2006-04-27 03:18:13 +05:30
|
|
|
|
2006-08-12 03:44:18 +05:30
|
|
|
def _set_dnd(self):
|
|
|
|
"""
|
|
|
|
Sets up drag-n-drop. The source and destionation are set by calling .target()
|
|
|
|
on the _DND_TYPE. Obviously, this means that there must be a _DND_TYPE
|
|
|
|
variable defined that points to an entry in DdTargets.
|
|
|
|
"""
|
|
|
|
|
|
|
|
dnd_types = [ self._DND_TYPE.target() ]
|
|
|
|
|
|
|
|
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types,
|
|
|
|
gtk.gdk.ACTION_COPY)
|
|
|
|
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
|
|
|
|
[self._DND_TYPE.target()],
|
|
|
|
gtk.gdk.ACTION_COPY)
|
|
|
|
self.list.connect('drag_data_get', self.drag_data_get)
|
|
|
|
self.list.connect('drag_data_received', self.drag_data_received)
|
|
|
|
|
|
|
|
def drag_data_get(self, widget, context, sel_data, info, time):
|
|
|
|
"""
|
|
|
|
Provide the drag_data_get function, which passes a tuple consisting of:
|
|
|
|
|
|
|
|
1) Drag type defined by the .drag_type field specfied by the value
|
|
|
|
assigned to _DND_TYPE
|
|
|
|
2) The id value of this object, used for the purpose of determining
|
|
|
|
the source of the object. If the source of the object is the same
|
|
|
|
as the object, we are doing a reorder instead of a normal drag
|
|
|
|
and drop
|
|
|
|
3) Pickled data. The pickled version of the selected object
|
|
|
|
4) Source row. Used for a reorder to determine the original position
|
|
|
|
of the object
|
|
|
|
"""
|
|
|
|
|
|
|
|
# get the selected object, returning if not is defined
|
|
|
|
obj = self.get_selected()
|
|
|
|
if not obj:
|
|
|
|
return
|
|
|
|
|
|
|
|
# pickle the data, and build the tuple to be passed
|
|
|
|
value = (self._DND_TYPE.drag_type, id(self), obj, self.find_index(obj))
|
|
|
|
data = pickle.dumps(value)
|
|
|
|
|
|
|
|
# pass as a string (8 bits)
|
|
|
|
sel_data.set(sel_data.target, 8, data)
|
|
|
|
|
|
|
|
def find_index(self, obj):
|
|
|
|
"""
|
|
|
|
returns the index of the object within the associated data
|
|
|
|
"""
|
|
|
|
return self.model.indexlist[obj]
|
|
|
|
|
|
|
|
def drag_data_received(self, widget, context, x, y, sel_data, info, time):
|
|
|
|
"""
|
|
|
|
Handle the standard gtk interface for drag_data_received.
|
|
|
|
|
|
|
|
If the selection data is define, extract the value from sel_data.data,
|
|
|
|
and decide if this is a move or a reorder.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if sel_data and sel_data.data:
|
|
|
|
d = Utils.fix_encoding(sel_data.data.replace('\0',' ').strip())
|
|
|
|
protocol,site,mfile,j,k,l = urlparse.urlparse(d)
|
|
|
|
if protocol == "file":
|
|
|
|
name = Utils.fix_encoding(mfile)
|
|
|
|
mime = Mime.get_type(name)
|
|
|
|
if not Mime.is_valid_type(mime):
|
|
|
|
return
|
|
|
|
photo = RelLib.MediaObject()
|
|
|
|
photo.set_path(name)
|
|
|
|
photo.set_mime_type(mime)
|
|
|
|
basename = os.path.basename(name)
|
|
|
|
(root,ext) = os.path.splitext(basename)
|
|
|
|
photo.set_description(root)
|
|
|
|
trans = self.dbstate.db.transaction_begin()
|
|
|
|
self.dbstate.db.add_object(photo, trans)
|
|
|
|
self.dbstate.db.transaction_commit(trans,
|
|
|
|
_("Drag Media Object"))
|
2006-08-12 23:49:25 +05:30
|
|
|
widget.emit_stop_by_name('drag_data_received')
|
2006-08-12 03:44:18 +05:30
|
|
|
|
2006-04-27 03:18:13 +05:30
|
|
|
def get_bookmarks(self):
|
|
|
|
return self.dbstate.db.get_media_bookmarks()
|
2005-08-14 10:01:29 +05:30
|
|
|
|
2006-03-06 05:09:20 +05:30
|
|
|
def define_actions(self):
|
|
|
|
PageView.ListView.define_actions(self)
|
|
|
|
self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
|
2006-05-02 11:20:46 +05:30
|
|
|
_('_Column Editor'), callback=self.column_editor)
|
2006-08-10 06:12:44 +05:30
|
|
|
self.add_action('FilterEdit', None, _('Media Filter Editor'),
|
|
|
|
callback=self.filter_editor,)
|
2006-04-27 03:18:13 +05:30
|
|
|
|
2006-08-10 06:12:44 +05:30
|
|
|
def filter_toggle(self, client, cnxn_id, etnry, data):
|
|
|
|
if Config.get(Config.FILTER):
|
|
|
|
self.search_bar.hide()
|
|
|
|
self.filter_pane.show()
|
|
|
|
active = True
|
|
|
|
else:
|
|
|
|
self.search_bar.show()
|
|
|
|
self.filter_pane.hide()
|
|
|
|
active = False
|
|
|
|
|
|
|
|
def filter_editor(self,obj):
|
|
|
|
from FilterEditor import FilterEditor
|
|
|
|
|
|
|
|
try:
|
|
|
|
FilterEditor('Media',const.custom_filters,
|
|
|
|
self.dbstate,self.uistate)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2006-03-06 05:09:20 +05:30
|
|
|
|
|
|
|
def column_editor(self,obj):
|
|
|
|
import ColumnOrder
|
|
|
|
|
2006-04-24 03:44:28 +05:30
|
|
|
ColumnOrder.ColumnOrder(
|
2006-04-24 09:36:17 +05:30
|
|
|
_('Select Media Columns'),
|
2006-04-24 03:44:28 +05:30
|
|
|
self.uistate,
|
|
|
|
self.dbstate.db.get_media_column_order(),
|
|
|
|
column_names,
|
|
|
|
self.set_column_order)
|
2006-03-06 05:09:20 +05:30
|
|
|
|
|
|
|
def set_column_order(self,list):
|
|
|
|
self.dbstate.db.set_media_column_order(list)
|
|
|
|
self.build_columns()
|
|
|
|
|
2005-08-14 10:01:29 +05:30
|
|
|
def column_order(self):
|
|
|
|
return self.dbstate.db.get_media_column_order()
|
|
|
|
|
|
|
|
def get_stock(self):
|
|
|
|
return 'gramps-media'
|
|
|
|
|
|
|
|
def build_widget(self):
|
|
|
|
base = PageView.ListView.build_widget(self)
|
|
|
|
vbox = gtk.VBox()
|
2006-06-20 02:31:57 +05:30
|
|
|
vbox.set_border_width(0)
|
2005-08-14 10:01:29 +05:30
|
|
|
vbox.set_spacing(4)
|
|
|
|
|
|
|
|
self.image = gtk.Image()
|
|
|
|
self.image.set_size_request(int(const.thumbScale),
|
|
|
|
int(const.thumbScale))
|
|
|
|
vbox.pack_start(self.image,False)
|
|
|
|
vbox.pack_start(base,True)
|
|
|
|
|
|
|
|
self.selection.connect('changed',self.row_change)
|
2006-08-12 03:44:18 +05:30
|
|
|
self._set_dnd()
|
2005-08-14 10:01:29 +05:30
|
|
|
return vbox
|
|
|
|
|
|
|
|
def row_change(self,obj):
|
2005-05-24 18:38:06 +05:30
|
|
|
handle = self.first_selected()
|
2005-12-23 07:30:35 +05:30
|
|
|
if not handle:
|
2006-08-05 01:06:18 +05:30
|
|
|
try:
|
|
|
|
self.image.clear()
|
|
|
|
except AttributeError:
|
|
|
|
# Working around the older pygtk
|
|
|
|
# that lacks clear() method for gtk.Image()
|
|
|
|
self.image.set_from_file(None)
|
2006-06-17 08:06:57 +05:30
|
|
|
else:
|
|
|
|
obj = self.dbstate.db.get_object_from_handle(handle)
|
|
|
|
pix = ImgManip.get_thumbnail_image(obj.get_path())
|
|
|
|
self.image.set_from_pixbuf(pix)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-08-14 10:01:29 +05:30
|
|
|
def ui_definition(self):
|
|
|
|
return '''<ui>
|
|
|
|
<menubar name="MenuBar">
|
|
|
|
<menu action="EditMenu">
|
|
|
|
<placeholder name="CommonEdit">
|
|
|
|
<menuitem action="Add"/>
|
|
|
|
<menuitem action="Edit"/>
|
|
|
|
<menuitem action="Remove"/>
|
|
|
|
</placeholder>
|
2006-03-06 05:09:20 +05:30
|
|
|
<menuitem action="ColumnEdit"/>
|
2006-08-10 06:12:44 +05:30
|
|
|
<menuitem action="FilterEdit"/>
|
2005-08-14 10:01:29 +05:30
|
|
|
</menu>
|
2006-04-27 03:18:13 +05:30
|
|
|
<menu action="BookMenu">
|
|
|
|
<placeholder name="AddEditBook">
|
|
|
|
<menuitem action="AddBook"/>
|
|
|
|
<menuitem action="EditBook"/>
|
|
|
|
</placeholder>
|
|
|
|
</menu>
|
2005-08-14 10:01:29 +05:30
|
|
|
</menubar>
|
|
|
|
<toolbar name="ToolBar">
|
|
|
|
<placeholder name="CommonEdit">
|
|
|
|
<toolitem action="Add"/>
|
|
|
|
<toolitem action="Edit"/>
|
|
|
|
<toolitem action="Remove"/>
|
|
|
|
</placeholder>
|
|
|
|
</toolbar>
|
|
|
|
<popup name="Popup">
|
|
|
|
<menuitem action="Add"/>
|
|
|
|
<menuitem action="Edit"/>
|
|
|
|
<menuitem action="Remove"/>
|
|
|
|
</popup>
|
|
|
|
</ui>'''
|
|
|
|
|
|
|
|
def add(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Add a new media object to the media list"""
|
|
|
|
import AddMedia
|
2006-04-29 04:43:15 +05:30
|
|
|
am = AddMedia.AddMediaObject(self.dbstate, self.uistate, [])
|
2003-09-10 19:08:02 +05:30
|
|
|
am.run()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-08-14 10:01:29 +05:30
|
|
|
def remove(self,obj):
|
|
|
|
handle = self.first_selected()
|
2005-12-23 07:30:35 +05:30
|
|
|
if not handle:
|
|
|
|
return
|
2005-08-14 10:01:29 +05:30
|
|
|
the_lists = Utils.get_media_referents(handle,self.dbstate.db)
|
2005-03-12 06:14:11 +05:30
|
|
|
|
2006-02-05 06:53:25 +05:30
|
|
|
ans = DeleteMediaQuery(handle,self.dbstate.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
|
|
|
|
2005-08-14 10:01:29 +05:30
|
|
|
def edit(self,obj):
|
|
|
|
handle = self.first_selected()
|
2005-12-23 07:30:35 +05:30
|
|
|
if not handle:
|
|
|
|
return
|
2005-08-14 10:01:29 +05:30
|
|
|
|
|
|
|
obj = self.dbstate.db.get_object_from_handle(handle)
|
2006-05-11 06:03:17 +05:30
|
|
|
try:
|
|
|
|
EditMedia(self.dbstate,self.uistate, [], obj)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2006-02-05 06:53:25 +05:30
|
|
|
|
|
|
|
class DeleteMediaQuery:
|
|
|
|
|
|
|
|
def __init__(self,media_handle,db,the_lists):
|
|
|
|
self.db = db
|
|
|
|
self.media_handle = media_handle
|
|
|
|
self.the_lists = the_lists
|
|
|
|
|
|
|
|
def query_response(self):
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.disable_signals()
|
|
|
|
|
|
|
|
(person_list,family_list,event_list,
|
|
|
|
place_list,source_list) = self.the_lists
|
|
|
|
|
|
|
|
for handle in person_list:
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in person.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
person.set_media_list(new_list)
|
|
|
|
self.db.commit_person(person,trans)
|
|
|
|
|
|
|
|
for handle in family_list:
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in family.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
family.set_media_list(new_list)
|
|
|
|
self.db.commit_family(family,trans)
|
|
|
|
|
|
|
|
for handle in event_list:
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in event.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
event.set_media_list(new_list)
|
|
|
|
self.db.commit_event(event,trans)
|
|
|
|
|
|
|
|
for handle in place_list:
|
|
|
|
place = self.db.get_place_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in place.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
place.set_media_list(new_list)
|
|
|
|
self.db.commit_place(place,trans)
|
|
|
|
|
|
|
|
for handle in source_list:
|
|
|
|
source = self.db.get_source_from_handle(handle)
|
|
|
|
new_list = [ photo for photo in source.get_media_list() \
|
|
|
|
if photo.get_reference_handle() != self.media_handle ]
|
|
|
|
source.set_media_list(new_list)
|
|
|
|
self.db.commit_source(source,trans)
|
|
|
|
|
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.remove_object(self.media_handle,trans)
|
|
|
|
self.db.transaction_commit(trans,_("Remove Media Object"))
|