# #####################################################################
# Open Text Exceed onDemand Client 8
# Copyright (c) 1997-2011 Open Text Corporation. All Rights Reserved.
# #####################################################################
# cde_setup
# Post install setup for CDE
# $Revision: 7613 $
# #####################################################################

. utils/cde_utils

cde_add_sig_at_offset()
{
  cde_data_criteria_content="${cde_data_criteria_content} ${2} string ${1} | " 
}

cde_create_content_string_for_supported_version()
{
  # Create cde_data_criteria_content string for the range 0..maxOffset 
  
  currentOffset=0
  
  while [ "${currentOffset}" -lt "${maxOffset}" ]
  do
    cde_add_sig_at_offset "${1}" "${currentOffset}"    
    currentOffset=`expr ${currentOffset} + 1`
  done 
}

cde_create_content_string()
{
  supportedVerCDE="${thisVer}"
  cdeVersionSig="[EOD${supportedVerCDE}CONNECTION]"  
  cde_create_content_string_for_supported_version "${cdeVersionSig}"  
  cde_data_criteria_content="${cde_data_criteria_content} ${maxOffset} string ${cdeVersionSig}" 
}

cde_create_dt_actionfile()
{
  cde_data_criteria_content=""
  
#  cde_create_content_string


  cat > "${dt_actionfile}" << __END_DTFILE__
#
# Exceed onDemand Client action and type information for CDE
#

DATA_ATTRIBUTES ${dt_data_type}
{
	DESCRIPTION ${docDescription}
	ICON        ${dt_eod_document_iconname}
	ACTIONS     Open
	MIME_TYPE   ${eod_mime_type}
	IS_TEXT     true
}

DATA_CRITERIA ${dt_data_type}_Criteria
{
	DATA_ATTRIBUTES_NAME ${dt_data_type}
	NAME_PATTERN *.${eodExt}
	CONTENT ${cde_data_criteria_content}
}

ACTION ${eod_action_name}
{
	LABEL       ${prodName}
	TYPE        COMMAND
	ICON           ${dt_eodiconname}
	WINDOW_TYPE NO_STDIO
	EXEC_STRING "${eodxc}" %Arg_1%
	DESCRIPTION ${eod_description}
}

ACTION Open
{
	ARG_TYPE   ${dt_data_type}
	TYPE       MAP
	MAP_ACTION ${eod_action_name}
}

__END_DTFILE__
}

cde_create_dt_frontpanelfile()
{
	# add EoD link to main panel's "Personal Applications" subpanel
	cat > ${dt_frontpanelfile} << __END_FPFILE__
CONTROL ${dt_eodname}
{
	LABEL          ${prodName}
	TYPE           file
	CONTAINER_TYPE SUBPANEL
	CONTAINER_NAME PersAppsSubpanel
	POSITION_HINTS last
	ICON           ${dt_eodiconname}
	FILE_NAME      ${dt_applinkfile}
	HELP_STRING ${eod_description}
}

__END_FPFILE__
}

handle_cde_these_icon_files()
{
	srcFile="${1}.${thisSuffix}"
	dstFile="${dt_icons_dir}/${1}_${thisVer}.${thisSuffix}"

	try cp "${srcFile}" "${dstFile}"
}


handle_cde_icon_files()
{
	for c1 in l m t
	do  
	  for c2 in b p
	  do
	    thisSuffix="${c1}.${c2}m"
	    handle_cde_these_icon_files "${dt_eodiconname_prefix}"
	    handle_cde_these_icon_files "${dt_eod_document_iconname_prefix}"
	  done
	done
}

cde_install_icons()
{
  [ ! -d "${dt_icons_dir}" ] && try mkdir -p "${dt_icons_dir}"
  
  handle_cde_icon_files
    
  # ------- Create Action and Data Type
  # (.dt file, specifying command, icon, description, .eod association, etc.)

  [ ! -d "${dt_types_dir}" ] && try mkdir -p "${dt_types_dir}"
}

cde_create_application_link()
{
	# -------- Create Application Link --------
	# (an empty executable file, connecting action .dt file to a menu)

	# /etc/dt or ~/.dt appmanager directories override /usr without including it,
	# so if we're creating a group that already exists we must make sure it
	# starts off equal to /usr, before we add eod
	[ ! -d "${dt_app_dir}" ] && cp -r "${dt_app_usr_dir}" "${dt_app_dir_root}"

	# if for some reason the copy failed then make an empty dir
	[ ! -d "${dt_app_dir}" ] && mkdir -p "${dt_app_dir}"

	echo "# ${dt_eodvername} application link file" > "${dt_applinkfile}"
	chmod +x "${dt_applinkfile}"
}

cde_install()
{
  cde_settings
  cde_install_icons
  cde_create_dt_actionfile
  cde_create_dt_frontpanelfile
	cde_create_application_link

	# make our changes show up without having to re-login
	cde_reloadactions
}

