# Copyright 2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

VALA_MIN_API_VERSION="0.48"
PYTHON_COMPAT=( python3_{9..11} )

inherit git-r3 meson vala gnome2-utils xdg python-any-r1

DESCRIPTION="Additional enhancements for the user experience. Contains many applets. Made for Budgie Desktop."
HOMEPAGE="https://github.com/UbuntuBudgie/${PN}"
EGIT_REPO_URI="https://github.com/UbuntuBudgie/${PN}.git"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS=""

IUSE_BUDGIE_EXTRAS_APPLETS="
	+budgie_extras_applets_all
	budgie_extras_applets_window-previews
	budgie_extras_applets_workspace-switcher
	budgie_extras_applets_hotcorners
	budgie_extras_applets_quicknote
	budgie_extras_applets_showtime
	budgie_extras_applets_countdown
	budgie_extras_applets_keyboard-autoswitch
	budgie_extras_applets_rotation-lock
	budgie_extras_applets_clockworks
	budgie_extras_applets_dropby
	budgie_extras_applets_kangaroo
	budgie_extras_applets_show-weather
	budgie_extras_applets_trash
	budgie_extras_applets_app-launcher
	budgie_extras_applets_recently-used
	budgie_extras_applets_take-a-break
	budgie_extras_applets_workspace-stopwatch
	budgie_extras_applets_extras-daemon
	budgie_extras_applets_quickchar
	budgie_extras_applets_fuzzyclock
	budgie_extras_applets_brightness-controller
	budgie_extras_applets_visualspace
	budgie_extras_applets_wallstreet
	budgie_extras_applets_applications-menu
	budgie_extras_applets_network-manager
	budgie_extras_applets_window-shuffler
"
IUSE="stateless networkmanager ${IUSE_BUDGIE_EXTRAS_APPLETS}"

# The idea is simple, either 'all' is on, or any of the others, none is not allowed.
# By default the 'all' is on, so most users are not affected by this.
# Kept it in list for to keep it readable.
#
# Also special case for networkmanager
REQUIRED_USE="
	|| ( budgie_extras_applets_all
			budgie_extras_applets_window-previews
			budgie_extras_applets_workspace-switcher
			budgie_extras_applets_hotcorners
			budgie_extras_applets_quicknote
			budgie_extras_applets_showtime
			budgie_extras_applets_countdown
			budgie_extras_applets_keyboard-autoswitch
			budgie_extras_applets_rotation-lock
			budgie_extras_applets_clockworks
			budgie_extras_applets_dropby
			budgie_extras_applets_kangaroo
			budgie_extras_applets_show-weather
			budgie_extras_applets_app-launcher
			budgie_extras_applets_recently-used
			budgie_extras_applets_take-a-break
			budgie_extras_applets_workspace-stopwatch
			budgie_extras_applets_extras-daemon
			budgie_extras_applets_quickchar
			budgie_extras_applets_fuzzyclock
			budgie_extras_applets_brightness-controller
			budgie_extras_applets_visualspace
			budgie_extras_applets_wallstreet
			budgie_extras_applets_applications-menu
			budgie_extras_applets_network-manager
			budgie_extras_applets_window-shuffler )
	budgie_extras_applets_network-manager? ( networkmanager )
	budgie_extras_applets_window-previews? ( budgie_extras_applets_extras-daemon )
	budgie_extras_applets_quickchar? ( budgie_extras_applets_extras-daemon )
	budgie_extras_applets_window-shuffler? ( budgie_extras_applets_extras-daemon )
	networkmanager? ( || ( budgie_extras_applets_network-manager budgie_extras_applets_all ) )
"

COMMON_DEPEND="
	>=gnome-extra/budgie-desktop-10.7
	dev-libs/appstream[vala]
	dev-libs/granite
	gui-libs/libhandy:1[vala]
	>=dev-libs/json-glib-1.0
	dev-libs/keybinder
	net-libs/libsoup:2.4
"

BDEPEND="${PYTHON_DEPS}"

DEPEND="
	${COMMON_DEPEND}
	budgie_extras_applets_all? ( ${COMMON_DEPEND} )
	networkmanager? (
		>=net-libs/libnma-1.8.0
		>=net-misc/networkmanager-1.24.0:=[modemmanager]
		>=net-misc/modemmanager-0.7 )
"

RDEPEND="
	!budgie_extras_applets_all? (
		budgie_extras_applets_clockworks? (
			media-gfx/cairosvg
			dev-python/svgwrite
			dev-python/pillow
		)

		budgie_extras_applets_countdown? (
			dev-python/psutil
			x11-themes/sound-theme-freedesktop
			media-sound/vorbis-tools
		)

		budgie_extras_applets_dropby? (
			dev-python/psutil
			dev-python/pyudev
			x11-misc/wmctrl
		)

		budgie_extras_applets_kangaroo? (
			x11-misc/xdg-utils
			dev-python/psutil
		)

		budgie_extras_applets_keyboard-autoswitch? (
			dev-python/psutil
			x11-misc/wmctrl
		)

		budgie_extras_applets_window-previews? (
			x11-apps/xinput
			x11-misc/xprintidle
		)

		budgie_extras_applets_quickchar? (
			x11-misc/wmctrl
			dev-python/pyperclip
			dev-python/python-xlib
		)

		budgie_extras_applets_hotcorners? ( x11-misc/xdotool )
		budgie_extras_applets_recently-used? ( x11-misc/xdg-utils )
		budgie_extras_applets_take-a-break? ( x11-misc/xprintidle )
		budgie_extras_applets_show-weather? ( sys-process/procps )
	)

	budgie_extras_applets_all? (
		dev-python/psutil
		dev-python/pyudev
		dev-python/pyperclip
		dev-python/python-xlib
		dev-python/svgwrite
		dev-python/pillow
		media-gfx/cairosvg
		media-sound/vorbis-tools
		sys-process/procps
		x11-apps/xinput
		x11-misc/wmctrl
		x11-misc/xdg-utils
		x11-misc/xdotool
		x11-misc/xprintidle
		x11-themes/sound-theme-freedesktop
	)
"

BDEPEND="$(vala_depend)"

PATCHES=(
	"${FILESDIR}"/exclude-network-applet-build-all.patch
)

python_check_deps() {
	return 0 # need to check if i want to add in test useflag or whether this has any point at all lol and next this section should be removed
	python_has_version "dev-python/python-dbusmock[${PYTHON_USEDEP}]"
}

pkg_setup() {
	python-any-r1_pkg_setup
}

src_prepare() {
	vala_setup
	default
}

src_configure() {
	local emesonargs=(
		-Dwith-zeitgeist=false
		$(meson_use stateless with-stateless)
		$(meson_use budgie_extras_applets_all with-default-schema)
		$(meson_use budgie_extras_applets_all build-recommended)
		$(meson_use budgie_extras_applets_window-previews build-wpreviews)
		$(meson_use budgie_extras_applets_workspace-switcher build-wswitcher)
		$(meson_use budgie_extras_applets_hotcorners build-hotcorners)
		$(meson_use budgie_extras_applets_quicknote build-quicknote)
		$(meson_use budgie_extras_applets_showtime build-showtime)
		$(meson_use budgie_extras_applets_countdown build-countdown)
		$(meson_use budgie_extras_applets_keyboard-autoswitch build-keyboard-autoswitch)
		$(meson_use budgie_extras_applets_rotation-lock build-rotation-lock)
		$(meson_use budgie_extras_applets_clockworks build-clockworks)
		$(meson_use budgie_extras_applets_dropby build-dropby)
		$(meson_use budgie_extras_applets_kangaroo build-kangaroo)
		$(meson_use budgie_extras_applets_show-weather build-weathershow)
		$(meson_use budgie_extras_applets_app-launcher build-app-launcher)
		$(meson_use budgie_extras_applets_recently-used build-recentlyused)
		$(meson_use budgie_extras_applets_take-a-break build-takeabreak)
		$(meson_use budgie_extras_applets_workspace-stopwatch build-workspacestopwatch)
		$(meson_use budgie_extras_applets_extras-daemon build-extrasdaemon)
		$(meson_use budgie_extras_applets_quickchar build-quickchar)
		$(meson_use budgie_extras_applets_fuzzyclock build-fuzzyclock)
		$(meson_use budgie_extras_applets_brightness-controller build-brightness-controller)
		$(meson_use budgie_extras_applets_visualspace build-visualspace)
		$(meson_use budgie_extras_applets_wallstreet build-wallstreet)
		$(meson_use budgie_extras_applets_applications-menu build-applications-menu)
		$(meson_use budgie_extras_applets_network-manager build-network-manager)
		$(meson_use budgie_extras_applets_window-shuffler build-window-shuffler)
		$(meson_use budgie_extras_applets_trash build-trash)
	)
	meson_src_configure
}

src_compile() {
	meson_src_compile
}

pkg_postinst() {
	xdg_pkg_postinst
	gnome2_schemas_update

	elog "In order for all the applets to appear after installation without relogging it is recommended to run the following as your current logged in user:"
	elog "  budgie-panel --replace &"
}

pkg_postrm() {
	xdg_pkg_postrm
	gnome2_schemas_update

	elog "In order for all the applets to be removed from the budgie-settings applets without relogging it is recommended to run the following as your current logged in user in budgie:"
	elog "  budgie-panel --replace &"
}