#!/bin/bash
# Copyright 2013 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 2.1.
#
# 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>

EXAMPLES_PATH="/usr/lib/ubuntu-ui-toolkit/examples"
NEW_EXAMPLES_PATH="$(qmake -query QT_INSTALL_EXAMPLES)/ubuntu-ui-toolkit/examples"

if [ -d "${NEW_EXAMPLES_PATH}" ]
then
    EXAMPLES_PATH=${NEW_EXAMPLES_PATH}
else
    if [ ! -d "${EXAMPLES_PATH}" ]
    then
        echo "Could not find the ubuntu-ui-toolkit examples, please make sure they are installed"
        exit 1
    fi
fi

echo "Copying ubuntu-ui-toolkit-gallery from ${EXAMPLES_PATH} to /tmp"
mkdir -p /tmp/ubuntu-ui-toolkit-gallery
cp -r "${EXAMPLES_PATH}/ubuntu-ui-toolkit-gallery/*" /tmp/ubuntu-ui-toolkit-gallery
echo "Opening project in Qt Creator"
qtcreator -client /tmp/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qmlproject &
echo "Launching the qmlscene"
/usr/bin/qmlscene $@ /tmp/ubuntu-ui-toolkit-gallery/ubuntu-ui-toolkit-gallery.qml &
