#!/bin/bash
# Small SED script for setting all the UI-version number in the various
# .ui files (generated by the Qt tools) to the Qt version installed on
# the executing machine
# It creates a backup of the changed file just in case :-)

# Get all .ui files
if [ $# -lt 1 ];then
	qmakev=`qmake -v 2>&1`
	qtv=`echo ${qmakev} | sed -e 's/.*(Qt \(.*\)).*/\1/g'`
else
	qtv=$1
fi
echo "Setting .ui files to Qt ${qtv}"
for file in `find . -name '*.ui'`;do
	UI=`grep -o -e "<UI version=\"[^\"]*\"" $file`
	length=${#UI}
	offset=`expr index "${UI}" "<UI version="`
	version=${UI:$offset+12:${length}-14}
	if [ $version != $qtv ]; then
		echo $file
		cp $file ${file}.qtvbak
		sed -e "s/<UI version=\"[^\"]*\"/<UI version=\"${qtv}\"/g#" ${file}.qtvbak > ${file}
		echo "(Backup: ${file}.qtvbak)";
	fi
done
