#!/bin/bash

# Copyright (C) 2007 PÃ¢ris Quentin
#                    Cassarin-Grand Arthur

# 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.

[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"

TITLE="Capture Plugin"

source "$POL_USER_ROOT/plugins/Capture/lib/Capture_lib"

# Starting debugging API
POL_Debug_Init

if [ "$AMD64_COMPATIBLE" == "True" ]; then
	cd "$POL_USER_ROOT/plugins/Capture/software/emul/ia32-linux/usr/lib/"
	ln -sf "$POL_USER_ROOT"/plugins/Capture/software/emul/ia32-linux/usr/lib/*.* "$POL_USER_ROOT"/plugins/Capture/software/usr/lib32/
	export PATH="$POL_USER_ROOT/plugins/Capture/software/usr/bin64/:${PATH}"
	export LD_LIBRARY_PATH="$POL_USER_ROOT/plugins/Capture/software/usr/lib/:$POL_USER_ROOT/plugins/Capture/software/usr/lib32/:${LD_LIBRARY_PATH}"
else
	cd "$POL_USER_ROOT/plugins/Capture/software/emul/ia32-linux/usr/lib/"
	ln -sf "$POL_USER_ROOT"/plugins/Capture/software/emul/ia32-linux/usr/lib/*.* "$POL_USER_ROOT"/plugins/Capture/software/usr/lib32/
	export PATH="$POL_USER_ROOT/plugins/Capture/software/usr/bin/:${PATH}"
	export LD_LIBRARY_PATH="$POL_USER_ROOT/plugins/Capture/software/usr/lib32/:${LD_LIBRARY_PATH}"
fi

# Check dependancies
which alsa || POL_Debug_Fatal "$(eval_gettext 'Please install alsa-base')" # Deb Package : alsa-base
which lame || POL_Debug_Fatal "$(eval_gettext 'Please install lame')" # Deb Package : lame
which oggenc || POL_Debug_Fatal "$(eval_gettext 'Please install vorbis-tools')" # Deb Package : vorbis-tools
which faac || POL_Debug_Fatal "$(eval_gettext 'Please install faac')" # Deb Package : faac
which ffmpeg || POL_Debug_Fatal "$(eval_gettext 'Please install LATEST ffmpeg')" # Deb Package : ffmpeg
which ffmpeg2theora || POL_Debug_Fatal "$(eval_gettext 'Please install ffmepg2theora')" # Deb Package : ffmepg2theora
which exiftool || POL_Debug_Fatal "$(eval_gettext 'Please install libimage-exiftool-perl')" # Deb Package : libimage-exiftool-perl
which oggz-merge || POL_Debug_Fatal "$(eval_gettext 'Please install oggz-tools')" # Deb Package : oggz-tools
which oggCat || POL_Debug_Fatal "$(eval_gettext 'Please install oggvideotools')" # Deb Package : oggvideotools
which mkvmerge || POL_Debug_Fatal "$(eval_gettext 'Please install mkvtoolnix')" # Deb Package : mkvtoolnix
which avimerge || POL_Debug_Fatal "$(eval_gettext 'Please install transcode-utils')" # Deb Package : transcode-utils
which MP4Box || POL_Debug_Fatal "$(eval_gettext 'Please install gpac')" # Deb Package : gpac
which recordmydesktop || POL_Debug_Fatal "$(eval_gettext 'Please install recordmydesktop')" # Deb Package : recordmydesktop
which mplayer || POL_Debug_Fatal "$(eval_gettext 'Please install mplayer')" # Deb Package : mplayer

POL_SetupWindow_Init

POL_SetupWindow_free_presentation "$TITLE" "$(eval_gettext 'This plugin will allow you to capture applications PlayOnLinux')"
menu_capture

exit
