# ===========================================================================
# Copyright (C) 2006 Ancient World Mapping Center
#
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 
# About Pleiades
# --------------
#
# Pleiades is an international research network and associated web portal and
# content management system devoted to the study of ancient geography. 
#
# See http://icon.stoa.org/trac/pleiades/wiki.
#
# Funding for the creation of this software was provided by a grant from the 
# U.S. National Endowment for the Humanities (http://www.neh.gov).
# ===========================================================================

from zope.interface import alsoProvides

from Products.PleiadesGeocoder.config import skin_name
from Products.PleiadesGeocoder.interfaces import IGeoserializableMembersFolder

def addSpatialMemberData(portal):
    """Add three properties to support IGeoItemSimple."""
    tool = portal.portal_memberdata
    if not hasattr(tool, 'srs'):
        tool.manage_addProperty('srs', 'EPSG:4326', 'string')
    if not hasattr(tool, 'geometryType'):
        tool.manage_addProperty('geometryType', '', 'string')
    if not hasattr(tool, 'spatialCoordinates'):
        tool.manage_addProperty('spatialCoordinates', '', 'string')

def markPortalMembersFolder(portal):
    tool = portal.portal_membership
    folder = tool.getMembersFolder()
    alsoProvides(folder, IGeoserializableMembersFolder)

def addPleiadesGeocoderSkin(portal):
    st = portal.portal_skins
    path = st.getSkinPath('Plone Default')
    path = [p.strip() for p in path.split(',')]
    if skin_name not in path:
        i = path.index('custom') + 1
        path.insert(i, skin_name)
    st.addSkinSelection('Plone Default', ','.join(path))

