# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

LOMIRI_PPA_COMMIT="0.4-7"
inherit lomiri

if [[ ${PV} == 9999 ]]; then
    KEYWORDS=""
    EGIT_REPO_URI="https://gitlab.com/ubports/development/core/${PN}.git"
    inherit git-r3
else
    KEYWORDS="~amd64"
    SRC_URI="https://gitlab.com/ubports/development/core/${PN}/-/archive/${PV}/${P}.tar.gz
            ${LOMIRI_PPA_URI}"
fi

DESCRIPTION="Lomiri desktop session definition."
HOMEPAGE="https://gitlab.com/ubports/development/core/${PN}"
LICENSE="LGPL-3"
SLOT="0"
IUSE="+qt6"
RESTRICT="test mirror"

DEPEND=""

RDEPEND="
    ${DEPEND}
    lomiri-base/lomiri
    >=lomiri-base/lomiri-schemas-0.1.11
    lomiri-extra/lomiri-keyboard
    sys-fs/inotify-tools
    x11-misc/xdg-user-dirs
    qt6? ( lomiri-base/xdg-desktop-portal-lomiri )
"

BDEPEND="
    dev-build/cmake
    dev-build/cmake-extras
    dev-build/samurai
"

PATCHES=(
    "${FILESDIR}"/${PN}-xdg-autostart.patch
)

src_prepare() {
    lomiri_src_prepare

    # mkcal and org.nemomobile.contacts.sqlite are not packaged: drop the
    # backend settings added by patches 2026-2028, later patches depend on
    # their context. If the sqlite contact backend is ever required, keep the
    # LOMIRI_CONTACT_BACKEND lines.
    sed -i \
        -e '/^export \(ALARM_BACKEND\|LOMIRI_ORGANIZER_BACKEND\|LOMIRI_CONTACT_BACKEND\)=/d' \
        -e '/^dbus-update-activation-environment --systemd \(ALARM_BACKEND\|LOMIRI_ORGANIZER_BACKEND\|LOMIRI_CONTACT_BACKEND\)=/d' \
        lomiri-session.in || die
}

src_configure() {
    local mycmakeargs=(
        -DENABLE_TOUCH_SESSION="OFF"
    )

    lomiri_src_configure
}