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

inherit gnome2 debug eutils

DESCRIPTION="Network configuration and management in an easy way. Desktop env independent"
HOMEPAGE="http://people.redhat.com/dcbw/NetworkManager/"
SRC_URI="http://ftp.gnome.org/pub/GNOME/sources/NetworkManager/0.6/NetworkManager-${PV}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ppc ~x86"
IUSE="crypt debug doc gnome"

RDEPEND=">=sys-apps/dbus-0.60
	>=sys-apps/hal-0.5
	sys-apps/iproute2
	>=dev-libs/libnl-1.0_pre6
	>=net-misc/dhcdbd-1.4
	>=net-wireless/wireless-tools-28_pre9
	>=net-wireless/wpa_supplicant-0.4.8
	>=dev-libs/glib-2.8
	>=x11-libs/libnotify-0.3.2
	gnome? ( >=x11-libs/gtk+-2.8
		>=gnome-base/libglade-2
		>=gnome-base/gnome-keyring-0.4
		>=gnome-base/gnome-panel-2
		>=gnome-base/gconf-2
		>=gnome-base/libgnomeui-2 )
	crypt? ( dev-libs/libgcrypt )"
	
DEPEND="${RDEPEND}
	dev-util/pkgconfig
	dev-util/intltool"

S=${WORKDIR}/NetworkManager-${PV}

DOCS="AUTHORS COPYING ChangeLog INSTALL NEWS README"
USE_DESTDIR="1"

G2CONF="${G2CONF} \
	`use_with crypt gcrypt` \
	`use_with gnome gnome` \
	--disable-more-warnings \
	--localstatedir=/var \
	--with-distro=gentoo \
	--with-dbus-sys=/etc/dbus-1/system.d \
	--enable-notification-icon"

src_unpack () {

	unpack ${A}
	cd ${S}
	# Consolidates not starting nscd if it isn't already
	# Adds in the dialup support (not working, but compiles)
	# Hopefully, doesn't start net.lo if it is already started.
	#epatch ${FILESDIR}/NM-Gentoo-checklo.patch
	# Use the kernel headers
	#epatch ${FILESDIR}/${PN}-use-kernel-headers.patch
	# Patch for madwifi, orinoco and ndiswrapper support.
	# Which doesn't apply properly to 0.6.4, will need to look into this later.
	#epatch ${FILESDIR}/nm-wireless-driver-workarounds-rml.patch
	# Patch from chutzpah@gentoo.org so that resolv.conf isn't modded 600
	#epatch ${FILESDIR}/nm-resolvconf-perms.patch
	# NM 0.6.2 requires dhcdbd be started rather than starting it.
	#epatch ${FILESDIR}/${PN}-0.6.2-update-initscript.patch
	# D-Bus changed dbus_connection_disconnect
	#epatch ${FILESDIR}/${PN}-0.6.4-dbus-close.patch
	# All of the above have been consolidated into one patch, including
	# changes to the backend which (should) allow it to read from conf.d/net
	# for settings...
	epatch ${FILESDIR}/${PN}-0.6.4-consolidated_changes.patch
	epatch ${FILESDIR}/${PN}-0.6.4-dbus-1.patch
}

src_install() {
	gnome2_src_install
	
	# Need to keep the /var/run/NetworkManager directory
	keepdir /var/run/NetworkManager
}
pkg_postinst() {
	gnome2_icon_cache_update
	elog "NetworkManager depends on the at_console property of DBUS"
	elog "to give permission to configure the networks.  This means"
	elog "you either need pam_console configured (see"
	elog "/usr/portage/sys-libs/pam/files/README.pam_console)"
	elog "or you need to touch /var/run/console/\$USERNAME for the user"
	elog "logging in at the console, and remove it when they log back"
	elog "out."
	elog "You will need to restart DBUS if this is your first time"
	elog "installing NetworkManager."
}
