# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit autotools eutils gnome2

DESCRIPTION="H.323 and SIP VoIP softphone"
HOMEPAGE="http://www.ekiga.org/"

SLOT="0"
LICENSE="GPL-2"
KEYWORDS="~alpha ~amd64 ~hppa ~ia64 ~ppc ~ppc64 ~sparc ~x86"
IUSE="avahi dbus debug doc eds gconf gnome gstreamer kde kontact ldap libnotify static xcap xv"

# gnome is actually useless if >=x11-libs/gtk+-2.14.0:2
RDEPEND=">=dev-libs/ptlib-2.5.2[debug=]
	>=net-libs/opal-3.5.2[debug=,wav]
	>=dev-libs/glib-2.8.0:2
	dev-libs/cyrus-sasl:2
	dev-libs/libsigc++:2
	dev-libs/libxml2:2
	>=x11-libs/gtk+-2.12.0:2
	avahi? ( >=net-dns/avahi-0.6.0 )
	dbus? ( >=dev-libs/dbus-glib-0.36 )
	eds? ( >=gnome-extra/evolution-data-server-1.2 )
	gconf? ( >=gnome-base/gconf-2.6.0:2 )
	gnome? ( || ( >=x11-libs/gtk+-2.14.0:2
			( >=gnome-base/libgnome-2.14.0
			>=gnome-base/libgnomeui-2.14.0 ) )
	)
	gstreamer? ( >=media-libs/gst-plugins-base-0.10.20:0.10
		media-libs/gst-plugins-bad )
	kde? ( kde-base/kdelibs )
	kontact? ( || ( kde-base/kdelibs:3.5 kde-base/kdepimlibs:4.1 ) )
	ldap? ( net-nds/openldap[sasl] )
	libnotify? ( x11-libs/libnotify )
	xv? ( x11-libs/libXv )
	xcap? ( >=net-libs/libsoup-2.4:2.4 )"

DEPEND="${RDEPEND}
	>=sys-devel/make-3.81
	>=dev-util/pkgconfig-0.12.0
	>=dev-util/intltool-0.35
	doc? ( app-text/scrollkeeper
		app-text/gnome-doc-utils )"

DOCS="AUTHORS ChangeLog FAQ NEWS README TODO"

pkg_setup() {
	if use kontact && !use kde; then
		eerror "You have to enable kde if you want to enable kontact"
	fi

	# dbus-service is always enable if dbus is enable, no reason to disable it
	G2CONF="${G2CONF}
		$(use_enable avahi)
		$(use_enable dbus)
		$(use_enable dbus dbus_service)
		$(use_enable debug gtk-debug)
		$(use_enable debug opal-debug)
		$(use_enable doc gdu)
		$(use_enable eds)
		$(use_enable gconf)
		$(use_enable gnome)
		$(use_enable gstreamer)
		$(use_enable kde)
		$(use_enable kontact kab)
		$(use_enable ldap)
		$(use_enable libnotify notify)
		$(use_enable static)
		$(use_enable xv)
		$(use_enable xcap)"
}

src_prepare() {
	# remove call to gconftool-2 --shutdown
	sed -i -e '/gconftool-2 --shutdown/d' Makefile.in \
		|| die "patching Makefile.in failed"

	# fix ekiga-helper dbus service .in file
	# should be fixed in next release
	sed -i -e 's/@PACKAGE_NAME@/ekiga/'\
		src/dbus-helper/org.ekiga.Helper.service.in \
		|| die "patching src/dbus-helper/org.ekiga.Helper.service.in failed"

	# configure.ac has many mistakes with this beta release
	epatch "${FILESDIR}"/${P}-configure.ac.patch

	eautoconf
}

pkg_postinst() {
	gnome2_pkg_postinst

	if ! use gnome; then
		ewarn "USE=-gnome is experimental, some weirdness with the UI and"
		ewarn "config keys should appear."
	fi
}