#!/bin/sh

APPS=$HOME/Applications
DOCS=$HOME/Documents

if [ -d $APPS -a "$1" != "-f" ]
then
    echo "You seem to already have a $APPS directory."
    echo "Assuming it is the QPE Applications directory. Exiting."
    exit 0
fi

if [ -d $HOME/Apps ]
then
    mv $HOME/Apps $APPS
else
    mkdir $APPS
fi

if [ -f $DOCS/addressbook.xml ]
then
    if [ -f $APPS/addressbook/addressbook.xml ]
    then
	echo "$DOCS/addressbook.xml conflicts with $APPS/addressbook/addressbook.xml"
	echo "Moving $DOCS/addressbook.xml to $HOME"
	mv $DOCS/addressbook.xml $HOME
    else
	mkdir $APPS/addressbook
	mv $DOCS/addressbook.xml $APPS/addressbook
    fi
fi

if [ -f $DOCS/datebooksettings.xml ]
then
    echo "$DOCS/datebooksettings.xml is obsolete"
    echo "Please re-set your datebook preferences"
    rm $DOCS/datebooksettings.xml
fi

if [ -f $DOCS/datebook.xml ]
then
    mkdir $APPS/databook
    mv $DOCS/datebook.xml $APPS/databook
fi

if [ -d $DOCS/qtmail ]
then
    mv $DOCS/qtmail $APPS/
fi

if [ -f $DOCS/todo.xml ]
then
    if [ -f $APPS/todolist/todolist.xml ]
    then
	mv $DOCS/todo.xml $HOME
	echo "$DOCS/todo.xml is superceded by  $APPS/todolist/todolist.xml"
	echo "$DOCS/todo.xml has been moved to $HOME"
    else
	echo "NOTE: $DOCS/todo.xml is obsolete. It will move to $APPS/todolist/todolist.xml"
	echo "when next you run the latest ToDo application."
    fi
fi

if [ ! -d $APPS/qimpen ]
then
    mkdir $APPS/qimpen
fi

if [ -f $DOCS/asciilower.qpt ]
then
    mv $DOCS/asciilower.qpt $APPS/qimpen
fi

if [ -f $DOCS/asciiupper.qpt ]
then
    mv $DOCS/asciiupper.qpt $APPS/qimpen
fi

if [ -f $DOCS/numeric.qpt ]
then
    mv $DOCS/numeric.qpt $APPS/qimpen
fi

if [ -d "$HOME/.qpe" ]
then
    if [ -d "$HOME/Settings" ]
    then
	mv $HOME/.qpe/* "$HOME/Settings"
	rmdir "$HOME/.qpe"
    else
	mv $HOME/.qpe "$HOME/Settings"
    fi
fi